What is an exclamation point in JavaScript?

后端 未结 2 415
你的背包
你的背包 2020-11-28 14:14

What does an exclamation mark before a function do?

Example:

return !loadDynamicBlock();
相关标签:
2条回答
  • 2020-11-28 14:24

    A ! negates an expression.

    In your example, if loadDynamicBlock() returned true, the function calling it would return false, and vice-versa: !true == false

    It can also be used to create actual booleans from JavaScript's ideas of truthy and falsy.

    var a = 5;
    !!(a - 5) === false;
    !!(a + 5) === true;
    
    0 讨论(0)
  • 2020-11-28 14:25

    The ! in Javascript inverts a boolean expression.

    0 讨论(0)
提交回复
热议问题