Skip to content

Commit

Permalink
Day 27: Hoising, Scoping
Browse files Browse the repository at this point in the history
  • Loading branch information
uttu-316 committed Nov 7, 2022
1 parent f5461ba commit 2a3352d
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions javascript/Day27/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
let k = 2;

function abc() {
let p = 3;
k = 4;
if (p < k) {
let h = 5;
console.log(h, p, k);
}
console.log(h);
}
console.log(k);
abc();

/*
var variables are functional scope variables
let variables are block scoper variables.
*/

console.log(hoist);
var hoist = "value";

myFunction();
let p = 3;
function myFunction() {
console.log("hello", p);
}

myFunction();

var myFunction = function () {
console.log("hello");
};

let a = 3;
let b = new Number(3);
let c = 3;

console.log(a == b);
console.log(a === b);
console.log(b === c);

a();

b();

function a() {
console.log("Hello");
}
var x = function () {
console.log("Bye");
};

var a = 4;

var g = 6;

console.log(a, g);

/* write your logic to swap values of two variables */

console.log(a, g); //6,4

var a = 4;
var j = 6;

console.log(a, j);
c = a;
a = j;
j = c;
console.log(a, j);

/* write your logic to swap values of two variables without using third variable */

a = a + b;
b = a - b;
a = a - b;
console.log(a, b);

0 comments on commit 2a3352d

Please sign in to comment.