Johan
Johan

Reputation: 35223

Evaluating the value of an empty string

Why is

console.log('' == false); //true

but

console.log('' === false); //false

Based on this the last row should return true, right?

Upvotes: 1

Views: 55

Answers (2)

Paul Aldred-Bann
Paul Aldred-Bann

Reputation: 6020

No, when you use === in javascript you're also comparing type, see this article which explains in more detail.

Upvotes: 2

Sune Trudslev
Sune Trudslev

Reputation: 974

Because === checks for types and the string is a string and false is a boolean.

Upvotes: 7

Related Questions