InterviewSolution
Saved Bookmarks
| 1. |
What are the different keywords to declare variables in TypeScript? |
|
Answer» var: Declares a function-scoped or global variable. You can optionally set its value during the DECLARATION. Its behavior and scoping RULES are similar to the var KEYWORD in JavaScript. For EXAMPLE, var foo = "bar";let: Declares a block-scoped local variable. Similar to var, you can optionally set the value of a variable during the declaration. For example, let a = 5;if (true) { let a = 10; console.log(a); // 10}console.log(a); // 5const: Declares a block-scoped constant value that cannot be changed after it’s initialized. For example, const a = 5;if (true) { a = 10; // Error: Cannot assign to 'a' because it is a constant.(2588)} |
|