2
2

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 5 years have passed since last update.

JavaScript で if ( a = b )

Last updated at Posted at 2015-01-20

ソース


// if ( a ==  b ) {} ←これでもないし
// if ( a === b ) {} ←これでもないよ

var a = 1;
var b = 2;

if ( a = b ) 
    alert(true);
else 
    alert(false);

alert('a:' + a + '\n' + 'b:' + b );

デモ

結果

alert1.png
alert.png

こういうこと

if ( a = b ) {}

↓これと同じ

a = b;
if ( a ) {}

aにbが代入されてから評価されるんだネ☆彡
C言語と一緒だヨ☆彡

…先輩、まぎらわしいんでやめてください( ´д`)

2
2
0

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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?