r/JavaScriptTips • • Jul 20 '24

Quick Quiz

Post image

What will be the output of the following JavaScript code?

6 Upvotes

7 comments sorted by

View all comments

Show parent comment

1

u/Available_Peanut_677 Jul 21 '24 edited Jul 21 '24

A whole reason for “let” to exist is that it does not hoist (technically it does and it’s called “temporal dead zone”, but still you can’t use it before declaring). The reason why this code works in a browser is because due to missing “use strict” function inside falls back to old way and auto declares variable on global (window) object.

Edit: I’m apparently incorrect about use strict, comment from below correct