Site icon Sudhanshu's Blog

What’s the difference between using “let” and “var” in JavaScript?

In simple terms var is function scoped and let is block scoped.

var

let

'use strict';
let me = 'foo';
let me = 'bar'; // SyntaxError: Identifier 'me' has already been declared
'use strict';
var me = 'foo';
var me = 'bar'; // No problem, `me` is replaced.

Thank you so much for reading.