Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does var name = 'jose' !== ''; return "true" and not true? [duplicate]

When I run var name = 'jose' !== ''; in my console, it returns "true"

Why does it return "true" as a string and not true as a boolean?

I tried it with a different variable name and it returns a boolean. i.e.: var bobby = 'bob' !== '';

like image 910
JCSNV Avatar asked May 11 '16 02:05

JCSNV


1 Answers

Because name is window.name. A special variable that is always a string. Type it into the console of any empty browser and you will get "".

You are reassigning its value in your statement.

https://developer.mozilla.org/en-US/docs/Web/API/Window/name

like image 105
ryanpcmcquen Avatar answered Nov 10 '22 19:11

ryanpcmcquen