JavaScript - Comments & VariablesTokens :It is a smallest unit of any programming language which consistsi. KeywordsIt is a predefined reserved words which can be understandable by the javscript engine. It should be always in lowercase.ii. IdentifiersName given by the programmer to the components of javascript like variables, functions etc.,Rules : iii. Variables / Literals :A named block of memory which is used to store a value is known as variables. It is a container to store data.Note : Variables :In JavaScript, variables are used to store and manage data. They are created using the var, let, or const keyword. 1. var Keyword : The var keyword is used to declare a variable. It has a function-scoped or globally-scoped behavior var x = 10;Syntax: va/let/const identifier (keywords) (variable declaration & initialization ) var a=10; Eg: var a = "Welcome to Tesdbacademy" var b = 10; var c = 12; var d = b + c; console.log(a); console.log(b); console.log(c); console.log(d);Output: Welcome to Tesdbacademy 10 12 22 2. let Keyword : The let keyword is a block-scoped variables. It’s commonly used for variables that may change their value. let y = "Hello"; Eg: let a = " Welcome to Tesdbacademy" let b = "joining"; let c = " 12"; let d = b + c; console.log(a); console.log(b); console.log(c); console.log(d);Output: Welcome to Tesdbacademy joining 12 joining 12 3. const Keyword : The const keyword declares variables that cannot be reassigned. It’s block-scoped as well. const PI = 3.14; Eg: const a = " Welcome to Tesdbacademy" console.log(a); const b = 400; console.log(b); const c = "12"; console.log(c); // Can’t change a value for a constant // c = "new" // console.log(c) will show errorOutput: Welcome to Tesdbacademy 400 12 Difference of var, let and const keyword?Scope Redeclare Reassign Hoisted Binds this ----- --------- --------- -------- ----------- var No Yes Yes Yes Yes let Yes No Yes No No const Yes No No No No « Previous Next Topic » (JS - Datatypes & Hoisting) |