var statement

JavaScript applications consist of statements with an appropriate syntax. A single statement may span multiple lines. Multiple statements may occur on a single line if each statement is separated by a semicolon. This isn’t a keyword, but a group of keywords.

If you have followed my previous posts, the editor i am using is VSCode with some extensions installed. If you have missed it, please follow the below link:

I am extensively using Quokka and Better comments plugins in VSCode to communicate the things.

//* — i am using this to highlight what exact operation i am trying to perform.

//! — i am using this to highlight language specific pitfalls and trying to highlight how it works.

//- i am using to highlight code and how JavaScript engine sees this.

Also the values in blue showing up towards the end in the below image is the output.

Just to re-iterate, the goal here is that visualising the below image anyone should be able to:

  1. Understand the concept.
  2. Know how to code the concept.
  3. Know how the output varies based on the code.

var statement:

Declaring and initializing a variable


Hoisting explained


Function and Global Scope

As description variable was not found in scope of function x, it went up to it’s next higher scope(global in this case) and found it. If it was not declared, it would have thrown Reference Error: description is not defined.

Function and Global Scope 2

Types of Declaration:

Types of var declarations