DEV Community

PUSHAN VERMA
PUSHAN VERMA

Posted on

Execution Context , Hoisting and Access by Value and Access by Referencce

*Execution Context *

//📌execution context - a environment , where javascript code is executed and evaluated

//global execution context - by default an execution provided by js ,i.e known as global execution context
//this is the place where the whole code resides.

//eg. consider a example of nesting a loop , then the first loop is global exec context and the rest are
// sub exec context

var a =3;
var b =5;

function sum(a,b)
{
return a+b;
}

var sum1 =sum(5,6);
var sum2=sum(a,b);
console.log(sum1);
console.log(sum2);

*Hoisting *

console.log(a);

greet();

var a =2

function greet()
{
console.log("Hello")
}

Access by Value and Access by reference

// 📌Primitive and Non Primitive data type

//📌 PRIMITIVE DATA TYPE
let a =2.5
console.log(a,typeof(a))

//👉 ans -->2.5 number

let b ="hello"
console.log(b,typeof(b));

//👉ans -->hello string

let c =true
console.log(c,typeof(c));

//👉ans -->true boolean

let d =undefined
console.log(d,typeof(d));

//👉 ans -->undefined undefined

let e =null
console.log(e,typeof(e));

// 👉ans-->null object

//📌Even though null is a primitive data type , it is given object in js (in js - it is treated as missing object)(it is considered as a bug in js till date)

//📌 NON PRIMITIVE DATA TYPE

let firstperson ="hitesh"

let secondperson =firstperson

console.log(firstperson);
console.log(secondperson);

// 👉ans-->
// hitesh
// hitesh

let firstperson1 ="hitesh"

let secondperson1 =firstperson

firstperson1="arshad"

console.log(firstperson1);
console.log(secondperson1);

//👉 ans -->
// arshad
// hitesh

https://github.com/pushanverma/notes/tree/main/webd

Top comments (0)