Skip to content

Commit 35b3664

Browse files
committed
js mcq interview
1 parent 6b98f0c commit 35b3664

7 files changed

Lines changed: 222 additions & 0 deletions

File tree

Linkdin Post/Js/condition.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
if([]){
2+
console.log("Nilaj is Absent")
3+
}else{
4+
5+
console.log("Nilaj is Present")
6+
}
7+
8+
9+
if([]==true){
10+
console.log("Nilaj is Absent")
11+
}else{
12+
13+
console.log("Nilaj is Present")
14+
}
15+
16+
17+
18+
19+
20+
21+
22+
/*
23+
let obj = {
24+
a: {
25+
b: undefined
26+
}
27+
}
28+
29+
console.log(obj?.a?.b?.c?.d ? "jithin" : "nilaj");//nilaj
30+
31+
32+
var abc = 25;
33+
if (function f() {}) {
34+
abc = abc + typeof f;
35+
}
36+
37+
console.log(abc);//25undefined
38+
*/

Linkdin Post/Js/equal.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
3+
4+
/*
5+
6+
Difference between == and ===?
7+
8+
== checks for value equality, while === checks for both value and type equality.
9+
== will perform type coercion if the types are different, while === will not.
10+
*/
11+
12+
13+
console.log(1 == "1") // true
14+
console.log(1 === "1") // false
15+
16+
17+
console.log(typeof NaN ==="number")//true
18+
19+
20+
21+
let a=["1","2","3"]
22+
console.log(a.indexOf("2"))

Linkdin Post/Js/forinof.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
// for..in loop
3+
// The for..in loop is used to iterate over the properties of an object.
4+
const person = {
5+
name: "John",
6+
age: 30,
7+
city: "New York"
8+
};
9+
10+
for (let i in person) {
11+
console.log(person[i]);
12+
}
13+
14+
15+
// for..of loop
16+
// The for..of loop is used to iterate over iterable objects like arrays, strings, etc.
17+
var numbers = [1, 2, 3];
18+
var sum = 0;
19+
for (let i of numbers) {
20+
//console.log();
21+
sum += i;
22+
23+
}
24+
console.log("Sum is " + sum);

Linkdin Post/Js/funmcq.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
function xyz(a, b, c) {
3+
4+
}
5+
console.log(xyz.length)//3
6+
function abc(x = 0, y, z) {
7+
8+
}
9+
console.log(abc.length)//0
10+
function pqr(d, e = 0, f) {
11+
12+
}
13+
console.log(pqr.length)//1
14+
function sef(y, z, b = 0) {
15+
16+
}
17+
18+
console.log(sef.length)//2
19+
function def(y = 0, x = 0, z = 0) {
20+
21+
}
22+
console.log(def.length)//0
23+
24+
25+
26+

Linkdin Post/Js/mcq.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
2+
console.log([1,2,3]+[4,5,6]); // [1,2,34,5,6] - concatenation of two arrays
3+
4+
console.log("1,2,3" + "4,5,6")
5+
6+
console.log([1,2,3] - [4,5,6])// NaN
7+
8+
console.log(1+"1"-1)// 10
9+
10+
let x=1;
11+
let y="1"
12+
console.log(x==y) // true
13+
console.log(x===y) // false
14+
15+
16+
console.log(typeof NaN ==="number") // type``of NaN is number is string ==="strtring" // true
17+
console.log(typeof[])// object
18+
19+
/*what is spread operator
20+
Spread operator is used to expand an iterable (like an array) into its individual elements.
21+
It is denoted by three dots (...).
22+
*/
23+
function foo(){
24+
return;
25+
{
26+
bar : "hello";
27+
28+
}
29+
}
30+
console.log(foo()) // undefined
31+
32+
/*
33+
Which of this looping structure is not supported in JavaScript?
34+
1. for..in
35+
2. for..of
36+
3. for..each
37+
4. for..loop
38+
Answer: 3. for..each
39+
*/
40+
41+
/* const can not be updated or re-declared within the same scope.
42+
const a=20;
43+
a=30; // TypeError: Assignment to constant variable.
44+
45+
46+
47+
48+
14. What is a promise in JavaScript?
49+
A) A function that always returns true
50+
B) A value that may be available now, later, or never
51+
C) A global object for HTTP requests
52+
D) A variable that can't be changed
53+
54+
Answer: B) A value that may be available now, later, or never
55+
*/
56+
57+
console.log(typeof null) // object
58+
59+
let a={}
60+
let b=a
61+
a.name="JS"
62+
console.log(b.name)// JS
63+
64+
/*
65+
let is a block-scoped variable declaration keyword in JavaScript.
66+
let can be updated
67+
but not re-declared within the same scope.
68+
*/
69+
let arr=[1,2,3];
70+
arr.length=0;
71+
console.log(arr) // [] - empty array
72+
73+
74+
const c = [1, 2];
75+
const d= [1, 2];
76+
console.log(JSON.stringify(c) === JSON.stringify(d));// true
77+
// JSON.stringify() converts a JavaScript object or value to a JSON string.

Linkdin Post/Js/trun.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function print(x){
2+
console.log(~x)
3+
}
4+
5+
print(2.8)
6+
print(2.1)
7+
print(2.9)
8+
print(6.25)
9+
print(0.25)
10+
print("-25.56")

Linkdin Post/Js/typeof.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
3+
let x
4+
console.log(typeof x)
5+
6+
let y=10
7+
console.log(typeof y)
8+
9+
let z=10.25
10+
console.log(typeof z)
11+
12+
let a=true
13+
console.log(typeof a)
14+
15+
let b="nilaj"
16+
console.log(typeof b)
17+
18+
let c=null
19+
console.log(typeof c)
20+
21+
let d=BigInt(8)
22+
console.log(typeof d)
23+
24+
let e=Symbol("hi")
25+
console.log(typeof e)

0 commit comments

Comments
 (0)