6

If I have something like:

let x = 20;
var z = 20;

will

x === z
RadleyMith
  • 1,313
  • 11
  • 22

2 Answers2

6

=== does not compare variables - it does compare values. Given that both your variables hold the same value (20), they will be "equal".

It does not matter for the equality how those variables were declared, only that both of them are in scope and have that value assigned when the === operation is evaluated. Which is the case in your example snippet.

Community
  • 1
  • 1
Bergi
  • 630,263
  • 148
  • 957
  • 1,375
5

Try it out and see for yourself...

(If nothing is displayed that is because you are using a browser that doesn't support let.)

"use strict";

let x = 20;
var z = 20;

document.write(x === z);

Read this answer for details about the differences between let and var:

The difference is scoping. var is scoped to the nearest function block (or global if outside a function block), and let is scoped to the nearest enclosing block (or global if outside any block), which can be smaller than a function block.

sdgluck
  • 24,894
  • 8
  • 75
  • 90