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,564
  • 146
  • 81
  • 122
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
  • 6,285
  • 3
  • 24
  • 37
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
Jack jdeoel
  • 4,554
  • 5
  • 26
  • 52