Skip to content

Commit 9dedc64

Browse files
committed
mcqjsday2
1 parent b4a9224 commit 9dedc64

File tree

1 file changed

+190
-13
lines changed

1 file changed

+190
-13
lines changed

JavaScript Interview/Most Imp MCQ/chatgpt.js

Lines changed: 190 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -277,41 +277,42 @@ console.log(sum(1,2,3,4))
277277
278278
console.log(typeof null);//object
279279
280-
281-
let a = 5;
282-
let b = "5";
280+
Day 1
281+
----------
282+
1. let a = 5;
283+
let b = "5";
283284
console.log(a == b); //true
284285
console.log(a === b); //false
285286
286287
287-
console.log(0.1 + 0.2 === 0.3); //false
288+
2. console.log(0.1 + 0.2 === 0.3); //false
288289
289290
290-
console.log([] == []);//false
291+
3. console.log([] == []);//false
291292
292-
console.log(typeof NaN); //number
293+
4. console.log(typeof NaN); //number
293294
294-
let x;
295+
5. let x;
295296
console.log(x + 2); //NAN
296297
297298
298-
let x;
299+
6. let x;
299300
console.log(x - 2); //NAN
300301
301302
302303
303-
let x;
304+
7. let x;
304305
console.log(x * 2); //NAN
305306
306307
307-
let x;
308+
8. let x;
308309
console.log(x / 2); //NAN
309310
310311
311-
console.log("5" - 2); //3 number
312+
9. console.log("5" - 2); //3 number
312313
console.log("5" + 2); //52 string
313314
314-
console.log(typeof typeof 1);//string typeof number number is string
315+
10. console.log(typeof typeof 1);//string typeof number number is string
315316
316317
console.log(typeof typeof 10.25);//string
317318
@@ -330,10 +331,175 @@ console.log(typeof typeof true);//string
330331
331332
console.log(3 > 2 > 1); //false true>1 type coreceion false
332333
333-
let a = [1, 2, 3];
334+
11.let a = [1, 2, 3];
334335
let b = a;
335336
b.push(4);
336337
console.log(a);//[1,2,3,4]
338+
339+
340+
Day 2
341+
__________
342+
343+
1. let a;
344+
console.log(a); //undefined
345+
console.log(typeof a); //undefined
346+
347+
348+
2. console.log(null == undefined); //true
349+
console.log(null === undefined); //false
350+
351+
352+
3. let x = "10";
353+
let y = 10;
354+
console.log(x + y); //1010
355+
console.log(x - y);//0
356+
357+
358+
4. console.log("2" > "12"); //true
359+
360+
console.log(1 > "12"); //false
361+
362+
console.log(1 < "12"); //true
363+
364+
console.log(null > "12"); //false
365+
366+
console.log(null < "12"); //true
367+
368+
console.log(undefined > "12"); //false
369+
370+
console.log(undefined < "12"); //false
371+
372+
console.log(-1 > "12"); //false
373+
374+
🧩 1. console.log("2" > "12"); // true
375+
376+
🧠 Explanation:
377+
378+
Both "2" and "12" are strings, not numbers.
379+
380+
When both sides are strings, JavaScript performs a lexicographical (dictionary-like) comparison — character by character from left to right.
381+
382+
"2" is compared with "1" first.
383+
384+
'2' (Unicode 50) is greater than '1' (Unicode 49).
385+
386+
✅ Output → true
387+
388+
🧩 2. console.log(1 > "12"); // false
389+
390+
🧠 Explanation:
391+
392+
Here, 1 is a number and "12" is a string.
393+
394+
When a number is compared to a string, JS converts the string to a number.
395+
396+
"12" → 12
397+
398+
399+
Then it compares 1 > 12 → false.
400+
401+
✅ Output → false
402+
403+
🧩 3. console.log(1 < "12"); // true
404+
405+
🧠 Explanation:
406+
407+
"12" is again converted to 12.
408+
409+
So 1 < 12 → true.
410+
411+
✅ Output → true
412+
413+
🧩 4. console.log(null > "12"); // false
414+
415+
🧠 Explanation:
416+
417+
When comparing null with a number or string, JavaScript first converts:
418+
419+
null → 0
420+
421+
"12" → 12
422+
423+
Then it compares 0 > 12 → false.
424+
425+
✅ Output → false
426+
427+
🧩 5. console.log(null < "12"); // true
428+
429+
🧠 Explanation:
430+
431+
Again, null → 0 and "12" → 12.
432+
433+
0 < 12 → true.
434+
435+
✅ Output → true
436+
437+
🧩 6. console.log(undefined > "12"); // false
438+
439+
🧠 Explanation:
440+
441+
undefined is not converted to 0 like null.
442+
443+
When undefined is compared to a number, it becomes NaN (Not a Number).
444+
445+
Any comparison with NaN (except !=) is false.
446+
447+
✅ Output → false
448+
449+
🧩 7. console.log(undefined < "12"); // false
450+
451+
🧠 Explanation:
452+
453+
Same reason as above — undefined → NaN.
454+
455+
Any comparison with NaN is false.
456+
457+
✅ Output → false
458+
459+
🧩 8. console.log(-1 > "12"); // false
460+
461+
🧠 Explanation:
462+
463+
"12" → number 12.
464+
465+
Compare -1 > 12 → false.
466+
467+
✅ Output → false
468+
469+
470+
471+
472+
5. let a = 1;
473+
let b = a++;
474+
console.log(a, b); //2 1
475+
476+
let c = 1;
477+
let d = ++c;
478+
console.log(c, d); //2 2
479+
480+
481+
482+
6.
483+
let a = 5;
484+
let b = "5";
485+
console.log(a != b); //false
486+
console.log(a !== b); //true
487+
488+
489+
7.
490+
console.log([] + []); //""
491+
console.log([] + {});// [object Object]
492+
console.log({} + []);//[object Object]
493+
494+
8.let value = "hello";
495+
console.log(value[1]);//e
496+
console.log(value[5]);// undefined
497+
498+
499+
9. let a = 0;
500+
console.log(Boolean(a)); //false
501+
console.log(!a);//true
502+
console.log(!!a);// false
337503
*/
338504

339505

@@ -344,4 +510,15 @@ console.log(a);//[1,2,3,4]
344510

345511

346512

513+
514+
515+
516+
517+
518+
519+
520+
521+
522+
523+
347524

0 commit comments

Comments
 (0)