10

What does an exclamation mark before a function do?

Example:

return !loadDynamicBlock();
Dave Newton
  • 156,572
  • 25
  • 250
  • 300
tmartin314
  • 3,785
  • 8
  • 38
  • 58

2 Answers2

26

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;
Dave Newton
  • 156,572
  • 25
  • 250
  • 300
7

The ! in Javascript inverts a boolean expression.

JaredPar
  • 703,665
  • 143
  • 1,211
  • 1,438