Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1f6e722

Browse files
Removed output based questions
1 parent 9c9acfa commit 1f6e722

File tree

1 file changed

+0
-254
lines changed

1 file changed

+0
-254
lines changed

‎README.md

Lines changed: 0 additions & 254 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ Every contribution counts, regardless of its size. I value and appreciate the ef
1515

1616
---
1717

18-
## Theoritical Questions
19-
2018
| S.No | Questions |
2119
| ------------- | ------------- |
2220
| 1 | [What is JavaScript](#1-what-is-javascript)
@@ -1369,255 +1367,3 @@ console.log(result); // output ========> output 1
13691367
13701368
**[:top: Scroll to Top](#javascript-interview-questions)**
13711369
1372-
1373-
## Output Based Questions
1374-
1375-
**1. What will be the output**
1376-
```js
1377-
let arr = [1, 2, 3, 4, 5, -6, 7];
1378-
arr.length = 0;
1379-
console.log(arr);
1380-
```
1381-
<details>
1382-
<summary><b>View Answer</b></summary>
1383-
<ul>
1384-
<li><b>Output</b> : [ ]</li>
1385-
<li><b>Reason</b> : The length of the array has been set to 0, so the array becomes empty.</li>
1386-
</ul>
1387-
</details>
1388-
1389-
**[:top: Scroll to Top](#javascript-interview-questions)**
1390-
1391-
**2. What will be the output**
1392-
```js
1393-
x = 10;
1394-
console.log(x);
1395-
var x;
1396-
```
1397-
<details>
1398-
<summary><b>View Answer</b></summary>
1399-
<ul>
1400-
<li><b>Output</b> : 10</li>
1401-
<li><b>Reason</b> : The declaration of the variable x is hoisted to the top of its scope.</li>
1402-
</ul>
1403-
</details>
1404-
1405-
**[:top: Scroll to Top](#javascript-interview-questions)**
1406-
1407-
**3. What will be the output**
1408-
```js
1409-
let a = { x: 1, y: 2 }
1410-
let b = a;
1411-
b.x = 3;
1412-
console.log(a);
1413-
console.log(b);
1414-
```
1415-
<details>
1416-
<summary><b>View Answer</b></summary>
1417-
<ul>
1418-
<li><b>Output</b> : { x: 3, y: 2 } { x: 3, y: 2 }</li>
1419-
<li><b>Reason</b> : 'a' and 'b' both are pointing to the same reference.</li>
1420-
</ul>
1421-
</details>
1422-
1423-
**[:top: Scroll to Top](#javascript-interview-questions)**
1424-
1425-
**4. What will be the output**
1426-
```js
1427-
for(var i = 0; i < 10; i++){
1428-
setTimeout(function(){
1429-
console.log("value is " + i);
1430-
})
1431-
}
1432-
```
1433-
<details>
1434-
<summary><b>View Answer</b></summary>
1435-
<ul>
1436-
<li><b>Output</b> : 10 times, "value is 10"</li>
1437-
<li><b>Reason</b> : "var" has a function scope, and there will be only one shared binding for the iterations. By the time the setTimeout function gets executed, the for loop has already completed and the value of the variable i is 10.</li>
1438-
</ul>
1439-
</details>
1440-
1441-
**[:top: Scroll to Top](#javascript-interview-questions)**
1442-
1443-
**5. What will be the output**
1444-
```js
1445-
for(let i = 0; i < 10; i++){
1446-
setTimeout(function(){
1447-
console.log("value is " + i);
1448-
})
1449-
}
1450-
```
1451-
<details>
1452-
<summary><b>View Answer</b></summary>
1453-
<ul>
1454-
<li><b>Output</b> : 10 times "value is" followed by the value of i in each iteration, from 0 to 9</li>
1455-
<li><b>Reason</b> : "let" has a block scope, and a new binding will be created for each iteration. Here, a new variable i is created and has a different value for each iteration of the loop.</li>
1456-
</ul>
1457-
</details>
1458-
1459-
**[:top: Scroll to Top](#javascript-interview-questions)**
1460-
1461-
**6. What will be the output**
1462-
```js
1463-
function hello() {
1464-
console.log("1");
1465-
setTimeout(() => {
1466-
console.log("2");
1467-
})
1468-
console.log("3");
1469-
}
1470-
hello();
1471-
```
1472-
<details>
1473-
<summary><b>View Answer</b></summary>
1474-
<ul>
1475-
<li><b>Output</b> : "1" followed by "3", and then after a small delay, "2"</li>
1476-
<li><b>Reason</b> : console.log("1") statement logs "1" to the console. Then setTimeout() function is set to execute the callback function in the next event loop iteration and logs "3" to the console.</li>
1477-
</ul>
1478-
</details>
1479-
1480-
**[:top: Scroll to Top](#javascript-interview-questions)**
1481-
1482-
**7. What will be the output**
1483-
```js
1484-
let f = "8";
1485-
let a = 1;
1486-
console.log((+f)+a+1);
1487-
```
1488-
<details>
1489-
<summary><b>View Answer</b></summary>
1490-
<ul>
1491-
<li><b>Output</b> : 10</li>
1492-
<li><b>Reason</b> : The expression (+f) is a shorthand way to convert the string value of f to a number. Therefore, (+f) evaluates to 8.</li>
1493-
</ul>
1494-
</details>
1495-
1496-
**[:top: Scroll to Top](#javascript-interview-questions)**
1497-
1498-
**8. What will be the output**
1499-
```js
1500-
let a = 10;
1501-
if(true){
1502-
let a = 20;
1503-
console.log(a, "inside");
1504-
}
1505-
console.log(a, "outside");
1506-
```
1507-
<details>
1508-
<summary><b>View Answer</b></summary>
1509-
<ul>
1510-
<li><b>Output</b> : 20, "inside" and 10, "outside"</li>
1511-
<li><b>Reason</b> : The variable "a" declared inside "if" has block scope and does not affect the value of the outer "a" variable.</li>
1512-
</ul>
1513-
</details>
1514-
1515-
**[:top: Scroll to Top](#javascript-interview-questions)**
1516-
1517-
**9. What will be the output**
1518-
```js
1519-
var a = "xyz";
1520-
var a = "pqr";
1521-
console.log(a)
1522-
```
1523-
<details>
1524-
<summary><b>View Answer</b></summary>
1525-
<ul>
1526-
<li><b>Output</b> : "pqr"</li>
1527-
<li><b>Reason</b> : Both the variables are declared using "var" keyword with the same name "a". The second variable declaration will override the first variable declaration.</li>
1528-
</ul>
1529-
</details>
1530-
1531-
**[:top: Scroll to Top](#javascript-interview-questions)**
1532-
1533-
**10. What will be the output**
1534-
```js
1535-
const arr1 = [1, 2, 3, 4];
1536-
const arr2 = [6, 7, 5];
1537-
const result = [...arr1, ...arr2];
1538-
console.log(result);
1539-
```
1540-
<details>
1541-
<summary><b>View Answer</b></summary>
1542-
<ul>
1543-
<li><b>Output</b> : [1, 2, 3, 4, 6, 7, 5]</li>
1544-
<li><b>Reason</b> : Spread operator (...) concatenates the two arrays into "result" array.</li>
1545-
</ul>
1546-
</details>
1547-
1548-
**[:top: Scroll to Top](#javascript-interview-questions)**
1549-
1550-
**11. What will be the output**
1551-
```js
1552-
const person1 = { name: 'xyz', age: 21 };
1553-
const person2 = { city: 'abc', ...person1 };
1554-
console.log(person2);
1555-
```
1556-
<details>
1557-
<summary><b>View Answer</b></summary>
1558-
<ul>
1559-
<li><b>Output</b> : { city: 'abc', name: 'xyz', age: 21 }</li>
1560-
<li><b>Reason</b> : Spread operator (...) copies all the properties from person1 into person2.</li>
1561-
</ul>
1562-
</details>
1563-
1564-
**[:top: Scroll to Top](#javascript-interview-questions)**
1565-
1566-
**12. What will be the output**
1567-
```js
1568-
console.log(5 < 6 < 7);
1569-
```
1570-
<details>
1571-
<summary><b>View Answer</b></summary>
1572-
<ul>
1573-
<li><b>Output</b> : true</li>
1574-
<li><b>Reason</b> : In JavaScript, the < operator evaluates expressions from left to right. First, the expression 5 < 6 is evaluated, resulting in true because 5 is less than 6. Then, the expression true < 7 is evaluated. In this case, JavaScript performs type coercion and converts true to the number 1. Therefore, the expression becomes 1 < 7, which is true.</li>
1575-
</ul>
1576-
</details>
1577-
1578-
**[:top: Scroll to Top](#javascript-interview-questions)**
1579-
1580-
**13. What will be the output**
1581-
```js
1582-
console.log(7 > 6 > 5);
1583-
```
1584-
<details>
1585-
<summary><b>View Answer</b></summary>
1586-
<ul>
1587-
<li><b>Output</b> : false</li>
1588-
<li><b>Reason</b> : In JavaScript, the > operator evaluates expressions from left to right. First, the expression 7 > 6 is evaluated, resulting in true because 7 is greater than 6. Then, the expression true > 5 is evaluated. In this case, JavaScript performs type coercion and converts true to the number 1. Therefore, the expression becomes 1 > 5, which is false.</li>
1589-
</ul>
1590-
</details>
1591-
1592-
**[:top: Scroll to Top](#javascript-interview-questions)**
1593-
1594-
**14. What will be the output**
1595-
```js
1596-
console.log(0 == false);
1597-
console.log(1 == true);
1598-
```
1599-
<details>
1600-
<summary><b>View Answer</b></summary>
1601-
<ul>
1602-
<li><b>Output</b> : true, true</li>
1603-
<li><b>Reason</b> : The == operator converts operands to a common type before making the comparison. In both the cases, the boolean value will be converted to a number, i.e., false is converted to 0 and true is converted to 1. So, the expression 0 == false is equivalent to 0 == 0 and 1 == true is equivalent to 1 == 1.</li>
1604-
</ul>
1605-
</details>
1606-
1607-
**[:top: Scroll to Top](#javascript-interview-questions)**
1608-
1609-
**15. What will be the output**
1610-
```js
1611-
console.log([11, 2, 31] + [4, 5, 6]);
1612-
```
1613-
<details>
1614-
<summary><b>View Answer</b></summary>
1615-
<ul>
1616-
<li><b>Output</b> : "11,2,314,5,6"</li>
1617-
<li><b>Reason</b> : The + operator is used for both addition and string concatenation. When you try to concatenate two arrays using the + operator, the arrays are converted to strings and then concatenated together. In this case, the arrays [11, 2, 31] and [4, 5, 6] are converted to strings as "11,2,31" and "4,5,6" respectively. Then, the two strings are concatenated, resulting in "11,2,314,5,6".</li>
1618-
</ul>
1619-
</details>
1620-
1621-
**[:top: Scroll to Top](#javascript-interview-questions)**
1622-
1623-
## Coding Exercise

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /