What is Javascript
Javascript is a programming language used to convert a static webpage to dynamic webpage
the browser understands the js code because every browser has js engine in chrome V8, Spider monkey in firefox ect
Scope of Keyword let , const , var
let block scope can only be used inside the block
const block scope can only be used inside the block
var is functional scope can be used anywhere inside and outside the block
{
var a=30
const c=10
let b=20
console.log("inside block",a,b,c)
}
console.log("outside block a",a)
console.log("outside block b",b)
console.log("outside block c",c)
Shadowing in JS
process of declaring a new variable with the same name as an existing variable in an inner scope, effectively hiding or "shadowing" the outer variable within that scope
function shadowexe()
{
let a=10
if(true)
{
let a=20
console.log(a)
}
console.log(a)
}
shadowexe()
output
20
10
here when we use the var in inner scope it throws the error of illegal shadowing
Decleration without intitialization
We can just declear a variable without initialization for let and var but should decleare and initialize for const
let a;
let b;
const a =10;
Top comments (0)