0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

TruthyとFalthy JavaScriptとPHPの違い

Posted at

Truthyとは

動的型付け言語において、真偽値型に変換されたらTrueになる値のこと

JSとPHPで異なる例

'0'(文字列の0)

JSではtrue、PHPではfalse

test.js
'0' == true // true
test.php
'0' == true // false

[](空配列)

JSではtrue、PHPではfalse

test.js
[] == true // true
test.php
[] == true // false

ちなみに、JSでは{}(空オブジェクト)もtrue

test.js
{} == true // true

公式

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?