Skip to content

Commit 66b36c7

Browse files
authored
Added question number 34 to 36
1 parent 555fa54 commit 66b36c7

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,3 +583,64 @@ console.log(filtered);
583583
</details>
584584

585585
**[:top: Scroll to Top](#javascript-output-based-interview-questions)**
586+
587+
**34. What will be the output**
588+
```js
589+
var x = 0;
590+
var y = 10;
591+
if(x){
592+
console.log(x);
593+
}
594+
if(y){
595+
console.log(y);
596+
}
597+
```
598+
<details>
599+
<summary><b>View Answer</b></summary>
600+
<ul>
601+
<li><b>Output</b> : 10</li>
602+
<li><b>Reason</b> : x = 0 is falsy and doesn't trigger the console.log(x), while y = 10 is truthy and triggers the console.log(y).</li>
603+
</ul>
604+
</details>
605+
606+
**[:top: Scroll to Top](#javascript-output-based-interview-questions)**
607+
608+
**35. What will be the output**
609+
```js
610+
const obj = {
611+
var1: 1,
612+
var2: 2
613+
};
614+
const { var1, var2 } = obj;
615+
console.log(var1, var2);
616+
```
617+
<details>
618+
<summary><b>View Answer</b></summary>
619+
<ul>
620+
<li><b>Output</b> : 1, 2</li>
621+
<li><b>Reason</b> : Object destructuring extracts the values of var1 and var2 from obj object and prints them using console.log(var1, var2)</li>
622+
</ul>
623+
</details>
624+
625+
**[:top: Scroll to Top](#javascript-output-based-interview-questions)**
626+
627+
**36. What will be the output**
628+
```js
629+
const user = {
630+
name: "Surbhi dighe",
631+
country: "India"
632+
};
633+
const { name: fullname, country } = user;
634+
console.log(fullname);
635+
console.log(name);
636+
```
637+
<details>
638+
<summary><b>View Answer</b></summary>
639+
<ul>
640+
<li><b>Output</b> : Surbhi Dighe, ReferenceError: name is not defined</li>
641+
<li><b>Reason for console.log(fullname)</b> : The name property from user is assigned to a local variable fullname.</li>
642+
<li><b>Reason for console.log(name)</b> : It gives an error because name was assigned to a local variable fullname and therefore name is not directly accessible.</li>
643+
</ul>
644+
</details>
645+
646+
**[:top: Scroll to Top](#javascript-output-based-interview-questions)**

0 commit comments

Comments
 (0)