Skip to content

Commit 2976a2a

Browse files
committed
Most Imp Js
1 parent 74d0bdb commit 2976a2a

1 file changed

Lines changed: 128 additions & 0 deletions

File tree

  • JavaScript Interview/Most Imp MCQ
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
3+
** Four Example of falsy values in JS
4+
5+
1. undefined
6+
var a;
7+
console.log(typeof(a));// undefined
8+
console.log(Boolean(a)); // false
9+
10+
11+
2. null
12+
var a = null;
13+
console.log(typeof(a));// object
14+
console.log(Boolean(a));// false
15+
16+
17+
3. NaN
18+
var a = NaN;
19+
console.log(typeof(a));// number
20+
console.log(Boolean(a));// false
21+
22+
23+
4. 0
24+
var a = 0;
25+
console.log(typeof(a));// number
26+
console.log(Boolean(a));// false
27+
28+
29+
5. "" (empty string)
30+
var a = "";
31+
console.log(typeof(a));// string
32+
console.log(Boolean(a));// false
33+
34+
35+
** let b;
36+
console.log(b);// undefined
37+
38+
39+
** var a;
40+
console.log(a);// undefined
41+
42+
43+
** const a;
44+
console.log(a);// SyntaxError: Missing initializer in const declaration
45+
46+
47+
**
48+
49+
console.log(a); // ReferenceError: Cannot access 'a' before initialization
50+
let a = 10;
51+
52+
53+
**
54+
console.log(a); // undefined
55+
var a; // undefined
56+
57+
58+
**
59+
console.log(a); // ReferenceError: Cannot access 'a' before initialization
60+
const a;
61+
62+
63+
**
64+
console.log(name);// undefined
65+
var name;
66+
67+
1. {
68+
let a = 1;
69+
let b = 2;
70+
71+
console.log(a);// 1
72+
console.log(b);// 2
73+
}
74+
75+
console.log(a); // ReferenceError: a is not defined
76+
console.log(b); // ReferenceError: b is not defined
77+
78+
79+
80+
2. {
81+
const a = 1;
82+
const b = 2;
83+
84+
console.log(a);// 1
85+
console.log(b);// 2
86+
}
87+
88+
console.log(a); // ReferenceError: a is not defined
89+
console.log(b);// ReferenceError: b is not defined
90+
91+
92+
93+
3. {
94+
var a = 1;
95+
var b = 2;
96+
97+
console.log(a);// 1
98+
console.log(b);// 2
99+
}
100+
101+
console.log(a); // 1
102+
console.log(b); // 2
103+
104+
105+
106+
4. console.log(a);// undefined
107+
var a = 1;
108+
console.log(a); // 1
109+
110+
111+
5. console.log(a); // referenceError: a is not defined
112+
let a = 1;
113+
console.log(a);
114+
115+
116+
6.
117+
console.log(a); // referenceError: a is not defined
118+
const a = 1;
119+
console.log(a);
120+
121+
122+
7.
123+
console.log(name);// undefined
124+
var name = 'John Doe';
125+
*/
126+
127+
128+

0 commit comments

Comments
 (0)