what is tilde in javascript code example
Example 1: meaning of tilde in javascript
//Combined with ~, it can do a boolean check if an item exists in a string value
var foo = "hello world";
if (~foo.indexOf("w")) {
// item in list
} else {
// item not in list
}
Example 2: what is use of tilde in js
//Bitwise operator
console.log(~-2); // 1
console.log(~-1); // 0
//Converting Strings to Numbers
console.log(~~"-1"); // -1
console.log(~~"0"); // 0