Javascript Data Type Question 1

Introduction

What is the output of the following code?

console.log(Boolean(undefined));
console.log(Boolean(null));
console.log(Boolean(""));


false
false
false

Note

We can use this coercion to our advantage

We can use if(x) to check for existence of a value for x

The only caveat is if x has a value 0, because Boolean(x) => false




PreviousNext

Related