5.3 Difference Between var, let and const in TypeScript - Tutorial Rays
TypeScript

5.3 Difference Between var, let and const in TypeScript

5.3 Difference Between var, let and const in TypeScript

What is difference between Var , Let and Const in TypeScript/JavaScript

1. Use or ‘var’ : TypeScript ‘var’ keyword is used to declare variable in Typescript. 1. If the variable is declared outside of function then it is considered global variable. 2. And if the variable is declared inside the function then its called local variable. 3. Block level accessibility is possible with ‘var’ keyword 2. Use of ‘’let : in TypeScript let keyword is used to declare variable like ‘var’ keyword. Using let keyword, you can declare variable as well as initialize it. 1. Let keyword is like var keyword, but it has limitation. Its declared at block level. 2. So, if a variable is declared inside a function using ‘let’ keyword then the variable will not be available inside the block. 3. Use of const : const keyword is used to declare a constant in typescript whose value cannot be changed throughout the application. 1. Const is normally used for global accessibility. 2. If you try to change value of const, the compiler will throw error.

Leave a Reply

Your email address will not be published. Required fields are marked *