LoginSignup
2
1

More than 5 years have passed since last update.

ショートカット演算

Last updated at Posted at 2018-02-25

・JavaScriptでは、論理演算子の時
    ・空白文字数値の0null、undefined
 の時はfalseとみなされます。
   

name変数は空白文字falseとみなされます。
右側は空白文字、数値の0、nullでないため日本太郎はtrueとみなされ代入されます。
よって日本太郎と表示されます。

name.js
var name = '';
name = name || '日本太郎';

console.log(msg);      // 結果 日本太郎
2
1
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
1