search

Home  >  Q&A  >  body text

javascript - what does if(aa) mean


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

黄舟黄舟2704 days ago1400

reply all(5)I'll reply

  • 漂亮男人

    漂亮男人2017-07-05 10:54:09

    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.

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-07-05 10:54:09

    Please search for keywords yourself: Implicit type conversion

    reply
    0
  • PHP中文网

    PHP中文网2017-07-05 10:54:09

    If you don’t understand, you can ask questions

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-07-05 10:54:09

    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.

    reply
    0
  • 迷茫

    迷茫2017-07-05 10:54:09

    if (aa) is equivalent to

    if (!!aa){
        console.log('here goes true'); 
    }

    reply
    0
  • Cancelreply