“JS Double Exclamation Mark” Código de respuesta

JS Double Exclamation Mark

// "!!" converts a value to a boolean, then inverts it and then inverts it again.
// So let's say you want to check the value for a given variable:
const num = null; 

if (num) { // false -> value is null -> evaluated as falsy
}
if (!num) { // true
}
if (!!num) { // false
}
// another example
const str = "Hello World";

if (str) { // true -> value is a "proper" (not empty) string -> evaluated as truthy
}
if (!str) { // false
}
if (!!str) { // true
}
Pl0erre

JavaScript Doble interrogatorio

let a = null;
const b = a ?? -1;		// Same as b = ( a != null ? a : -1 );
console.log(b);		  	// output: -1
//OR IF
let a = 9;
const b = a ?? -1;
console.log(b);  		// output: 9

//PS.,VERY CLOSE TO '||' OPERATION IN FUNCTION, BY NOT THE SAME
Lazurite

Respuestas similares a “JS Double Exclamation Mark”

Preguntas similares a “JS Double Exclamation Mark”

Más respuestas relacionadas con “JS Double Exclamation Mark” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código