7

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' !== '';

Pang
  • 9,073
  • 146
  • 84
  • 117
JCSNV
  • 99
  • 5

2 Answers2

6

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

ryanpcmcquen
  • 5,857
  • 3
  • 22
  • 35
0

variable name .It refers to window.name, which is the name of the window.

Also variable document

window.name ,window.document [can't change var name from being window.name, which is a string]

don't use name as a global variable.

Eg

var name = {Name : "dd"};
console.log(name.Name);//Since it's a primitive won't work
David Jaw Hpan
  • 4,511
  • 3
  • 24
  • 50