What is an exclamation point in JavaScript?

What does an exclamation mark before a function do?

Example:

return !loadDynamicBlock();

Answers:

Answer

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;
Answer

The ! in Javascript inverts a boolean expression.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.