r/javascript • • May 28 '19

What are some JavaScript things beginners don't know?

333 Upvotes

383 comments sorted by

View all comments

Show parent comments

4

u/DougWebbNJ May 28 '19

If "outside of the block" is the same as "at the top-level of the function's block", then let, const, and var are equivalent. That's the behavior I assumed Aswole was trying to achieve, by switching const/let to var without moving the variable definition.

1

u/aust1nz May 28 '19

Thanks for clarifying! You're right, and I think my reply was unclear -- you can declare a variable using let at the top of a function and reassign it within a block, if you want to completely avoid using var.

1

u/Aswole May 29 '19

You correctly interpreted my poorly worded comment.