Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions Hoisting, scope & etc/arrowFunction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Q12 - Arrow Function VS Regular Function

// ▶ Syntax

function square(num) {
console.log(num * num);
}

const square = (num) => {
return num * num;
};

// ▶ Implicit Return Keyword

const square = (num) => num * num;

// ▶ Arguments

function fn() {
console.log(arguments);
}

fn(1, 2, 4);

const fnArr = () => {
console.log(arguments);
};

// ▶ "this" Keyword

let user = {
username: "Bhavya Khatri",
rc1: () => {
console.log("You can do it" + this.username);
},
rc2: () => {
console.log("You can do it" + this.username);
},
};

user.rc1();
user.rc2();
62 changes: 62 additions & 0 deletions Hoisting, scope & etc/function.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Function in JavaScript

// Q1 What is Function Declarations?

function square(num) {
return num * num;
}

// This is also called function statement or function defination

/* ------------------------------------------------------------------------------------------------------------------------------------*/

// Q2 What is Function Expression?
// Ans- When we store a function inside of a variable is called function expression

const square1 = function (num) {
return num * num;
};

/* ------------------------------------------------------------------------------------------------------------------------------------*/

// Q3 What is Annonymos Function?
// Ans- Function which has no name.This annonymos function can be passed as callback

const squareNew = function (num) {
return num * num;
};

console.log(squareNew(5));

/* ------------------------------------------------------------------------------------------------------------------------------------*/

// Q4 What are First class Functions?

function square5(num) {
return num * num;
}

function displaySquare(fn) {
console.log("square is" + fn(5));
}

displaySquare(square5)(
/* ------------------------------------------------------------------------------------------------------------------------------------*/

// Q5 What is IIFE?
// Ans IIFE:- Imediately Invoked Function Expression

function square6(nums) {
console.log(nums * nums);
}
)(8)(
/* ------------------------------------------------------------------------------------------------------------------------------------*/

// Q6 IIFE- o/p based questions

function (x) {
return (function (y) {
console.log(x);
})(2);
}
)(1);
7 changes: 7 additions & 0 deletions Hoisting, scope & etc/functionScope.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Q7 Function Scope - o/p based questions

for (let i = 0; i < 5; i++) {
setTimeout(function () {
console.warn(i);
}, i * 1000);
}
16 changes: 16 additions & 0 deletions Hoisting, scope & etc/hoisting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Q8 - Function Hoisting

function functionName() {
console.log("Bhavya Khatri");
}
functionName();

// Q9- Function Hoisting - o/p Based Questions

var x = 21;
var fun = function () {
console.log(x);
var x = 20;
};

fun();
14 changes: 14 additions & 0 deletions Hoisting, scope & etc/iife.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Q5 What is IIFE?
// Ans IIFE:- Imediately Invoked Function Expression

(function square6(nums) {
console.log(nums * nums);
})(8)(
// Q6 IIFE- o/p based questions

function (x) {
return (function (y) {
console.log(x);
})(2);
}
)(1);
16 changes: 16 additions & 0 deletions Hoisting, scope & etc/params.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Q10 Params VS Arguments

function square(num) {
// Params or Parameter
console.log(num * num);
}

square(6); // Arguments

// Q11 Params VS Arguments - O/P Based Questions

const fn = (a, x, y, ...numbers) => {
console.log(x, y, numbers);
};

fn(5, 6, 3, 7, 8, 9, 2);
18 changes: 18 additions & 0 deletions Hoisting, scope & etc/script.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Hoisting,, Scope, callback & Arrow functions etc</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<h1>Hoisting, Scope, callback & Arrow functions etc.</h1>
<script src="function.js"></script>
<script src="iife.js"></script>
<script src="functionScope.js"></script>
<script src="hoisting.js"></script>
<script src="params.js"></script>
<script src="arrowFunction.js"></script>
</body>
</html>
11 changes: 11 additions & 0 deletions Hoisting, scope & etc/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
body {
background-color: thistle;
font-family: sans-serif;
background-image: url("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRy2XP0KdpeXiauf0T1eC-YmKHg0RpDt8qSKQ&usqp=CAU");
background-repeat: no-repeat;
}

h1 {
display: flex;
justify-content: center;
}