check if value is set javascript code example
Example 1: javascript check if variable exists
if (typeof myVar !== 'undefined') {
// myVar is defined
}
Example 2: javascript check if set
if (typeof variable !== 'undefined') {
// the variable is defined
}
//or
if (typeof variable === 'undefined') {
// variable is undefined
}
Example 3: check if set has value js
const mySet = new Set();
// Add value to set
mySet.add(15);
console.log(mySet.has(33)) // expected output: false
cosole.log(mySet.has(15)) // expected output: true