Skip to content

Commit 9473c04

Browse files
author
wakidurrahman
committed
docs: scope
1 parent c451e7d commit 9473c04

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

docs/interview-questions.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ obj['c'];
5252
5353
```
5454

55-
5655
`Q003:` Explain `arrays` in JavaScript.
5756

5857
Answer: An `array` is an object that holds values (of any type) not particularly in named properties/keys, but rather in numerically indexed positions:
@@ -74,3 +73,14 @@ arr.length? // 3
7473
typeof arr; // "object";
7574
7675
```
76+
77+
`Q004:` What is `scope` in JavaScript?
78+
79+
Answer: In JavaScript, each function gets its own scope. Scope is basically a collection of variables as well as the rules for how those variables are accessed by name. Only code inside that function can access that function's scoped variables.
80+
81+
1. A variable name has to be unique within the same scope.
82+
2. A scope can be nested inside another scope.
83+
3. If one scope is nested inside another, code inside the innermost scope can access variables from either scope.
84+
85+
86+
`Q005:` What is `scope` in JavaScript?

0 commit comments

Comments
 (0)