21 before variable javascript

Solutions on MaxInterview for 21 before variable javascript by the best coders in the world

showing results for - " 21 before variable javascript"
Dot
10 Feb 2020
1// ! before a boolean variable will reverse the value:
2var test = true;
3console.log(test); // True
4console.log(!test); // False
5
6// In JavaScript, every value has an inherent boolean value.
7// If you use ! on a string, for instance, it will convert the value
8// to a bool. This is useful to see if the string exists:
9var stringTest1 = "hello!";
10var stringTest2 = "";
11console.log(stringTest1); // hello!
12console.log(!stringTest1); // False
13console.log(stringTest2); // 
14console.log(!stringTest2); // True