JSの弱いタイプは、変数がIF条件で真であるか偽であるかなど、多くのことが混乱していると人々に感じさせます。非ブールタイプの変数が強くタイプされた言語のIF条件に配置されている場合、タイプ変換が必要ですが、JSはそれを必要としません。以下にテストして、IF条件で一般的な変数タイプのパフォーマンスをテストしましょう。
!function test1(){<span style = "color:#ff0000;"> var a、b = -1、c = 1、d = 0、e = null、f = undefined、g = ''、h = ""; </span> if(!a){console.log( 'a ='+a)} if(!b){console。 console.log( "c ="+c)} if(!d){console.log( "d ="+d)} if(!e){console.log( "e ="+e)} if(!f){console.log( "f ="+f)} if(!g){console.log(! console.log( "h ="+h)}}()さまざまな変数タイプが設定され、それぞれ条件の場合に配置されます
実行結果
a =未定義
d = 0
E = null
f =未定義
g =
h =
i = false