Answers for "! before variable javascript"

1

! before variable javascript

// ! before a boolean variable will reverse the value:
var test = true;
console.log(test); // True
console.log(!test); // False

// In JavaScript, every value has an inherent boolean value.
// If you use ! on a string, for instance, it will convert the value
// to a bool. This is useful to see if the string exists:
var stringTest1 = "hello!";
var stringTest2 = "";
console.log(stringTest1); // hello!
console.log(!stringTest1); // False
console.log(stringTest2); // 
console.log(!stringTest2); // True
Posted by: Guest on May-05-2021

Code answers related to "! before variable javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language