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.

暗黙的型変換

Last updated at Posted at 2023-05-16

変数を調べるときの調べる方法

console.log(typeof val)

function printTypeAndValue(val){
console.log(typeof val,val);
}

文字列と数値の暗黙的結合
let a = 0;
let b = '1' + a;
printTypeAndValue(b);
コンソール結果 string,10 文字列が優先される

数値と文字列の暗黙的結合
let c = 15 - b;
コンソール結果 number,5 数値が優先される

数値とNULLの暗黙的結合
let d = c - null;
コンソール結果 number,5 nullが数値の0に暗黙的に変換される

数値とTrueの暗黙的結合
let e = d - true;
コンソール結果 number,4 trueが数値の1に暗黙的に変換される

0
0
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
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?