Javascript double exclamation

"foo" "foo"!"foo" false!"foo" true ' '0' / false 0 ' / true 0 '0' / true false 'false' / false false '0' / true false undefined / false false null / false null undefined / true " trn". Is the logical negation or "not" operator! Because I really don't see what point it was trying to make.

Will negate the value,.e.!true yields false and vice versa. / That doesn't actually answer the question. It is typically used with, boolean (logical) values.

N1!true /!t returns false n2!false /!f returns true n3!' /!f returns true n4!'Cat' /!t returns false Double NOT (!) It is possible to use a couple of NOT operators in series to explicitly force the conversion of any value to the corresponding boolean primitive. Returns false if its single operand can be converted to true; otherwise, returns true.

See the following truth table: Javascript also gets really weird when it comes to NaN values. In JavaScript, the values false, null, undefined, 0, -0, NaN, and ' (empty string) are "falsy" values.

Operator (!undefined) yields false, so in effect!undefined converts undefined to false. Sorry, could you elaborate your last comment a bit?

This converts a value to a boolean and ensures a boolean type. And this is the only case I can think of off the top of my head where! If a value can be converted to false, the value is so-called falsy. If a value can be converted to true, the value is so-called truthy.

I have editted this into my answer. To explicitly convert its return value (or any expression in general) to the corresponding boolean value, use a double NOT operator or the Boolean constructor. Would behave differently.

The conversion is based on the "truthyness" or "falsyness" of the value (see truthy and falsy ). It's a way of casting a "truthy" or "falsy" value to true or false, respectively.

When used with non-Boolean values, it returns false if its single operand can be converted to true; otherwise, returns true. For example,!undefined will first convert undefined to false and then negate it, yielding true. The logical, nOT (!) operator (logical complement, negation) takes truth to falsity and vice versa.

Operator can be used with operands that are not Boolean values, it can still be considered a boolean operator since its return value can always be converted to a boolean primitive. Programming Languages Javascript Double exclamation (!) in javascript it is, nOT a javascript operator it coerces an object into boolean type 0, null, undefined - false other - true.