var and let Angular 2 1 1024x473 1 - Difference between VAR and LET Angular 2

Difference between VAR and LET Angular 2

Posted on

On this put up we’ll see how var key phrase in sort script is totally different from let key phrase. We are going to use quite simple program to clarify the distinction between var vs let key phrases in angular 2 typescript.

VAR Key phrase Utilization

We are going to write a easy program with var key phrase as give under

Run this under command to compile sort script

Run the code-main.js file utilizing node.js

Variable ‘i’ is asserted inside loop however nonetheless we will use it exterior loop which make its out there for different code as properly inside doSomething() operate.

LET Key phrase Utilization

We are going to change the key phrase var –> let as given under.

Once more compile the code as we did earlier.

Now we have compilation error which recommend variable ‘i’ isn’t seen exterior loop which means scope is restricted to nearest scope. We will this error in visible studio code as properly when writing code.

You may see exterior loop variable is marked error and you may see error message for those who hover mouse pointer on it.

var and let Angular 2 1 1024x473 - Difference between VAR and LET Angular 2

 

 

Supply projectgeek.com