A Comprehensively Short Guide to let, var and this

Bear

Back in September, I wrote this story on var, let and the keyword this

However, some people still found it hard to distinguish between the difference — or rather, they wanted something that was more visually accessible. So I decided to change the format a little for today’s piece.

Here is your comprehensively short guide/notes version to let, var and this

var, let and this recap:

  • JavaScript is a lexical language — this means inheritance flow inwards
  • if a variable is declared at the root level, it becomes a global variable and accessible by everything
  • var is scoped to the nearest function block, meaning the closest { } pair that’s attached to a function.
  • let is scoped to the nearest closing block, meaning the closest { } pair, regardless of what it is.
  • this lets you access variables that are outside the closing block and function scopes. Depending on what you used (i.e. let or var), it can change the way results are returned.

And that’s basically var, let and this in nutshell.

React. JavaScript. Angular. Firebase. ☕🍕☕🍕☕🍕 Follow me at twitter.com/dottedsquirrel to get notified about my latest articles & antics on and off Medium.

Sign up for hashmap

By hashmap

Becoming better developers together Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store