js is boolean 1

js is boolean

if (typeof variable === "boolean"){
  // variable is a boolean
}

Here is what the above code is Doing:
1. We’re checking if the type of the variable is a string.
2. If it is, we’re printing out “variable is a string”.
3. If it isn’t, we’re checking if the type of the variable is a number.
4. If it is, we’re printing out “variable is a number”.
5. If it isn’t, we’re checking if the type of the variable is a boolean.
6. If it is, we’re printing out “variable is a boolean”.
7. If it isn’t, we’re printing out “variable is something else”.

Similar Posts