Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 185 additions & 0 deletions code-snippets/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
</div>

<ol>

<li>

**What will be the Output??**
Expand Down Expand Up @@ -76,4 +77,188 @@ TeamDevKode ()

---

<li>

**What is the output ?**

```JS
const animal = {
animal_name: "cat",
action: function () {
console.log(`${this.animal_name} is doing action`);
}
};

setTimeout(animal.action, 1000);

```

- A: `cat is doing action`
- B: `undefined is doing action`
- C: `null is doing action`
- D: `error`

<br/>

<details>
<summary><b>Answer</b></summary>
<p>

#### Option: B

</p>
</details>

</li>

---

<li>

**What is the output ?**

```JS
const animal = {
animal_name: "cat",
action: function () {
console.log(`${this.animal_name} is doing action`);
}
};

setTimeout(function () {
animal.action();
}, 1000);

```

- A: `cat is doing action`
- B: `undefined is doing action`
- C: `null is doing action`
- D: `error`

<br/>

<details>
<summary><b>Answer</b></summary>
<p>

#### Option: A

</p>
</details>

</li>

---

<li>

**What is the output ?**

```JS
const animal = {
animal_name: "cat",
action: function () {
console.log(`${this.animal_name} is doing action`);
}
};

let func = animal.action.bind(animal);
setTimeout(func, 1000);

```

- A: `null is doing action`
- B: `undefined is doing action`
- C: `cat is doing action`
- D: `error`

<br/>

<details>
<summary><b>Answer</b></summary>
<p>

#### Option: C

</p>
</details>

</li>

---

<li>

**What is the output ?**

```JS
function getFunc() {
let value = "Hey !";

let func = new Function("console.log(value)");

return func;
}

getFunc()();

```

- A: `Hey !`
- B: `error: value is not defined`
- C: `null`

<br/>

<details>
<summary><b>Answer</b></summary>
<p>

#### Option: B

</p>
</details>

</li>

---

<li>

**What is the output ?**

```JS
function getFunc() {
let value = "Hello Friends !";
let func = () => {
alert(value);
};
return func;
}

getFunc()();

```

- A: `Hey !`
- B: `error: value is not defined`
- C: `Hello Friends !`
- D: `null`

<br/>

<details>
<summary><b>Answer</b></summary>
<p>

#### Option: C

</p>
</details>

</li>

---

</ol>