Skip to content

Commit

Permalink
control flow code files
Browse files Browse the repository at this point in the history
  • Loading branch information
hiteshchoudhary committed May 19, 2023
1 parent 83055e1 commit 5b168f5
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 0 deletions.
12 changes: 12 additions & 0 deletions 03_basics/04_iife.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Immediately Invoked Function Expressions (IIFE)


(function chai(){
// named IIFE
console.log(`DB CONNECTED`);
})();

( (name) => {
console.log(`DB CONNECTED TWO ${name}`);
} )('hitesh')

52 changes: 52 additions & 0 deletions 04_control_flow/one.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// if
const isUserloggedIn = true
const temperature = 41

// if ( temperature === 40 ){
// console.log("less than 50");
// } else {
// console.log("temperature is greater than 50");
// }

// console.log("Execute");
// <, >, <=, >=, ==, !=, ===, !==

// const score = 200

// if (score > 100) {
// let power = "fly"
// console.log(`User power: ${power}`);
// }

// console.log(`User power: ${power}`);


// const balance = 1000

// if (balance > 500) console.log("test"),console.log("test2");

// if (balance < 500) {
// console.log("less than 500");
// } else if (balance < 750) {
// console.log("less than 750");

// } else if (balance < 900) {
// console.log("less than 750");

// } else {
// console.log("less than 1200");

// }

const userLoggedIn = true
const debitCard = true
const loggedInFromGoogle = false
const loggedInFromEmail = true

if (userLoggedIn && debitCard && 2==3) {
console.log("Allow to buy course");
}

if (loggedInFromGoogle || loggedInFromEmail) {
console.log("User logged in");
}
29 changes: 29 additions & 0 deletions 04_control_flow/switch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// switch (key) {
// case value:

// break;

// default:
// break;
// }

const month = "march"

switch (month) {
case "jan":
console.log("January");
break;
case "feb":
console.log("feb");
break;
case "march":
console.log("march");
break;
case "april":
console.log("april");
break;

default:
console.log("default case match");
break;
}
43 changes: 43 additions & 0 deletions 04_control_flow/truthy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const userEmail = []

if (userEmail) {
console.log("Got user email");
} else {
console.log("Don't have user email");
}

// falsy values

// false, 0, -0, BigInt 0n, "", null, undefined, NaN

//truthy values
// "0", 'false', " ", [], {}, function(){}

// if (userEmail.length === 0) {
// console.log("Array is empty");
// }

const emptyObj = {}

if (Object.keys(emptyObj).length === 0) {
console.log("Object is empty");
}

// Nullish Coalescing Operator (??): null undefined

let val1;
// val1 = 5 ?? 10
// val1 = null ?? 10
// val1 = undefined ?? 15
val1 = null ?? 10 ?? 20



console.log(val1);

// Terniary Operator

// condition ? true : false

const iceTeaPrice = 100
iceTeaPrice <= 80 ? console.log("less than 80") : console.log("more than 80")

0 comments on commit 5b168f5

Please sign in to comment.