6

If I have something like:

let x = 20;
var z = 20;

will

x === z
0

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.