javascript - Judgment condition question
PHP中文网
PHP中文网 2017-05-19 10:20:52
0
4
422
if(+g == 1){
    //do something
    }

How to explain g == 1 in this code?

PHP中文网
PHP中文网

认证0级讲师

reply all(4)
巴扎黑

Unary operator+表示 正号, g如果是一个非法的数,+g将得到NaN, such as string:

console.log(+'hello')
// > NaN

If it is a legal number, then it is 取他的正值:

console.log(+-3)  // +(-3)
// > -3

Then determine whether it is equal to 1.

伊谢尔伦

After adding + in front of the variable, the variable will be converted into a number and numerical operations can be performed

滿天的星座

The meaning of converting variables into numbers.

巴扎黑

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template