What exactly is Type Coercion in Javascript?

前端 未结 10 1098
后悔当初
后悔当初 2020-11-22 04:36

What exactly is type coercion in Javascript?

For example, on the use of == instead of ===?

10条回答
  •  囚心锁ツ
    2020-11-22 05:15

    var str = 'dude';
    console.log(typeof str); // "string"
    console.log(!str); // false
    console.log(typeof !str); // "boolean"
    

    Example of a variable which is initially declared as a string being coerced into boolean value with the ! operator

提交回复
热议问题