Skip to content

Commit 4a98f54

Browse files
committed
interviw questions day 2 js
1 parent 7cf46a5 commit 4a98f54

8 files changed

Lines changed: 111 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
/*
3+
Asynchronous functions allow JavaScript to handle time-consuming tasks efficiently without blocking
4+
the execution of other code.
5+
Common techniques include using callbacks, Promises, and async/await for handling asynchronous operations.
6+
*/
7+
8+
9+
console.log("1"-1);//0
10+
11+
setTimeout(function() {console.log(10)}, 10);//10
12+
13+
console.log(2);//2
14+
15+
setTimeout(function() {console.log(12)}, 10);//12
16+
setTimeout(function() {console.log(11)}, 9);//11
17+
18+
// 0 2 11 10 12

JavaScript Interview/Day 2/demo.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
console.log('1'+1)//11
2+
/*
3+
The + operator is used for string concatenation when one of the operands is a string.
4+
*/
5+
console.log("1"+1)//11
6+
7+
console.log(1 +"1")//11
8+
console.log(1-"1")//0
9+
10+
11+
/*
12+
The - operator is used for subtraction, and it does not concatenate strings.
13+
When using - with a string and a number, JavaScript tries to convert the string to a number.
14+
15+
loosely coupling
16+
17+
*/
18+
console.log("1"-1)//0
19+
20+
//addition arihematic
21+
console.log(1+1)//2
22+
23+
/*
24+
25+
When using the * operator with a string and a number,
26+
JavaScript tries to convert the string to a number before performing the multiplication.
27+
*/
28+
console.log("3"*2)//
29+
30+
/*
31+
The / operator is used for division, and it behaves similarly to the
32+
* operator in that it also converts the string to a number before performing the division.
33+
34+
35+
*/
36+
console.log("3"/2)// 1.5
37+
console.log("6"/2)//3
38+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
/*
3+
The first console.log subtracts 1 from the string "1", which JavaScript implicitly converts to the number 1, resulting in 0.
4+
5+
The setTimeout function schedules the execution of a function that logs 10 to the console after a 10-millisecond delay.
6+
7+
The final console.log outputs 2 immediately.
8+
*/
9+
console.log("1"-1);
10+
11+
setTimeout(function() {console.log(10)}, 10);
12+
13+
console.log(2);// 0 2 10
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const arr = [1, 2, 3, 4, 5, 6];
2+
const greaterThanThree = arr.filter(item => item > 3);
3+
4+
console.log(greaterThanThree); // Output: [4, 5, 6]

JavaScript Interview/Day 2/find.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
3+
// find method is use to find a specific value from arraay
4+
5+
const arr = [1, 2, 3, 4, 5];
6+
const found = arr.find(element => element > 3);
7+
8+
console.log(found); // Output: 4

JavaScript Interview/Day 2/map.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const arr = [1, 2, 3, 4, 5];
2+
const newArr = arr.map(item => item > 2); // Just returns true or false based on the condition
3+
4+
console.log(newArr);//[ false, false, true, true, true ]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const arr = [1, 2, 3, 4, 5];
2+
const newArr = arr.reduce((acc ,curr)=> acc*curr);
3+
4+
console.log(newArr);//120

JavaScript Interview/Day 2/var.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
let var & const
3+
-----------------
4+
var: variable can be redeclared & updated. A global scope variable before 2015 we used var
5+
6+
7+
but in 2015 in javascript has new features called ES6 and we use the following keyword
8+
9+
let:variable can not be re-declared but can be updated. block scope variable.
10+
11+
const: variable can not be re-declared or updated.A block scope variable.
12+
13+
*/
14+
15+
16+
// line by line execution
17+
18+
//a = 10;
19+
console.log(a);//undefined
20+
var a;
21+
a=10
22+
//let a; This code will throw a ReferenceError because you're trying to assign a value to a before it's initialized due to the temporal dead zone.

0 commit comments

Comments
 (0)