forked from bittu1040/JavaScript-Coding-and-Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10-shortcut.js
44 lines (33 loc) · 1.18 KB
/
10-shortcut.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// javascript shortcut which will be helpful
// short circuiting
// ternary operator
// nullish coalescing operator
// optional chaining
// short circuiting
// It refers to the evaluation of logical operator && (AND) and || (OR) where the evaluation of the entire expression stops as soon as the result comes.
// It solely on the first operand and evaluates from left to right.
// as per And operator: If any one of the operand is false then the result is false
// as per Or operator: If any one of the operand is true then the result is true
let isSwitchOn = true;
let hasBulb ="Yes";
let isLightOn = isSwitchOn && hasBulb;
console.log(isLightOn); // "Yes"
let age = 18;
let allowedAccess = age >= 13 && age <= 65;
console.log(allowedAccess); // true
let username = "admin";
let password = "secret";
let loginSuccess = username === "admin" && password === "secret";
console.log(loginSuccess); // true
const a = 0 && 5;
console.log(a); // 0
const b = 40 && 5;
console.log(b); // 5
const c = 0 || 5;
console.log(c) // 5
const d = 4 || 5;
console.log(d); // 4
const userInput= "";
const defaultValue = "Bittu";
const input= userInput || defaultValue;
console.log(input)