javascript - what does if(aa) mean
黄舟
黄舟 2017-07-05 10:52:09
0
5
1416


if(aa) What exactly is it judging? (I was looking at other people’s code screenshots with these judgments. I didn’t understand the abbreviation)
Is it to judge whether aa is null or undefined??

Let’s assume Figure 2:

What is the if(aa) here judging??

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(5)
漂亮男人

First of all, the syntax of if expression is:

if (expression)
    statement

expressionexpression is executed. If the result is truthy (true value), statement is executed. If it is falsy (false value), it is not executed.

truthy and falsy in JavaScript. The false value is

false
undefined
null
0
-0
NaN
"" // the empty string

Except for these, the rest are true values.

我想大声告诉你

Please search for keywords yourself: Implicit type conversion

洪涛

If you don’t understand, you can ask questions

过去多啦不再A梦

This is an if judgment expression. The specific syntax is as follows:

if (condition)
   statement1
[else
   statement2]

The value in condition needs to be of Boolean type true or false

In Javascript, the following values ​​will be implicitly converted to false:
0, -0, null, false, NaN, undefined, "" (empty string)
Other values ​​will be converted to true, please note that "false "It's also true.

迷茫

if (aa) is equivalent to

if (!!aa){
    console.log('here goes true'); 
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template