Skip to content

Commit 7e9b57c

Browse files
committed
Add arguments coding question
1 parent 11275f5 commit 7e9b57c

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

README.md

+29
Original file line numberDiff line numberDiff line change
@@ -11762,6 +11762,35 @@ console.log(arr.sort(Intl.Collator().compare)); //['Wann', 'wäre', 'Woche', 'w
1176211762
</details>
1176311763
1176411764
**[⬆ Back to Top](#table-of-contents)**
11765+
11766+
11767+
#### 85. What is the output of below code?
11768+
11769+
```javascript
11770+
function func(a, b=2) {
11771+
console.log(arguments.length);
11772+
}
11773+
11774+
func(undefined);
11775+
func();
11776+
```
11777+
11778+
- 1: 1, 0
11779+
- 2: 0, 0
11780+
- 3: 0, 1
11781+
- 4: 1, 1
11782+
11783+
<details><summary><b>Answer</b></summary>
11784+
<p>
11785+
11786+
##### Answer: 1
11787+
11788+
If a function is called with `undefined`, the `undefined` value is treated as a parameter. But if the function is not passed with any parameters, the `arguments` object doesn't include any argument eventhough the function has default function parameter. Hence, the function invocation with `undefined` has one argument and function call without any arguments has 0 agruments.
11789+
11790+
</p>
11791+
</details>
11792+
11793+
**[⬆ Back to Top](#table-of-contents)**
1176511794
1176611795
## Disclaimer
1176711796

0 commit comments

Comments
 (0)