TypeScript Tutorials - 05 TypeScript Variable Declaration

Опубликовано: 03 Август 2017
на канале: Ashman Malhotra
325
4

“Typescript Variable Declaration”

We can declare variables in TypeScript the same we used to declare a variable in JavaScript. We can make use of var keyword to declare variables.

In this lesson, I will discuss problems associated with variable declaration method of JavaScript using var keyword. I will help you understand my point with a very simple example.

So, let’s create a TypeScript file.

The problem with this method is that we can access variable i outside the scope of for block. If you will recall the strict Object Oriented Language that you may have studied in past, variables are inaccessible outside their scope block.

In the current scenario, the scope of the variable i is within the for loop. Therefore, it should not be accessible outside the for loop block.

How can we resolve this problem?
The solution is let keyword. With let keyword, we can implement Block-Scoping. I will make changes in the code to help you understand what I mean.

In our current code, I am going to replace var keyword with let keyword.

   • TypeScript Tutorials - 05 TypeScript ...  
*********************************************************************
Please subscribe to my channel:
https://www.youtube.com/c/ashmanmalho...
*********************************************************************
Thank you for watching my video on "TypeScript Introduction"
*********************************************************************
Contact: [email protected] for training inquiries
*********************************************************************
"TypeScript Programming Basics" | "TypeScript variableIntroduction" | "Strongly Types TypeScript” | “Typed Script”