You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. They use a concise syntax which makes them shorter and easier to read as compared to traditional function expressions
164
-
2. They do not bind their own this value, but instead inherit the this value from the enclosing lexical scope (i.e., the scope in which it is defined)
165
+
2. They do not bind their own this value, but instead inherit the this value from the enclosing lexical scope
165
166
3. They do not have "prototype" property and hence cannot be used as a constructor
166
167
4. If the arrow function body consists of a single expression, that expression will be implicitly returned, without the need for a return statement.
167
168
5. If an arrow function has only one parameter, the parentheses around the parameter list can be omitted.
@@ -180,7 +181,6 @@ const arr = [1,2,3];
180
181
const [num1, num2, num3] = arr;
181
182
console.log(num1); // output =====> 1
182
183
console.log(num2); // output =====> 2
183
-
console.log(num3); // output =====> 3
184
184
```
185
185
**[:top: Scroll to Top](#javascript-interview-questions)**
186
186
@@ -261,14 +261,12 @@ Hoisting is a default behavior in JavaScript where variable and function declara
261
261
console.log(a); // output =====> undefined
262
262
var a =10;
263
263
```
264
-
The output of above code will be undefined because the declaration of "a" is hoisted to the top of the scope, but the initialization happens later in the code.
265
264
266
265
```javascript
267
266
a=10;
268
267
console.log(a); // output =====> 10
269
268
var a;
270
269
```
271
-
The output of above code will be 10 because the variable "a" is hoisted to the top of the scope and its value is assigned before console.log
272
270
273
271
**Function hoisting**
274
272
```javascript
@@ -277,7 +275,7 @@ function demo() {
277
275
console.log('demo console');
278
276
}
279
277
```
280
-
The output of above code will be "demo console" because the function declaration is hoisted to the top of the scope, allowing it to be called before it is declared in the code.
278
+
281
279
```diff
282
280
**Note**
283
281
+ Only function declarations are hoisted, not the function expressions.
**[:top: Scroll to Top](#javascript-interview-questions)**
701
697
702
698
### 41. Is JavaScript case-sensitive
@@ -1021,6 +1017,44 @@ try {
1021
1017
1022
1018
**[:top: Scroll to Top](#javascript-interview-questions)**
1023
1019
1020
+
### 68. What is an anonymous function
1021
+
An anonymous function is a function that does not have a name. It is common to assign anonymous functions to a variable or use them as callback functions.
1022
+
```js
1023
+
const sayHi = function() {
1024
+
console.log("Hi there!!");
1025
+
};
1026
+
sayHi();
1027
+
```
1028
+
**[:top: Scroll to Top](#javascript-interview-questions)**
1029
+
1030
+
### 69. What is a first order function
1031
+
A first order function is a function that does not take any other functions as arguments and does not return any function as its result.
1032
+
```js
1033
+
function sayHello() {
1034
+
console.log("A first order function")
1035
+
}
1036
+
sayHello();
1037
+
```
1038
+
1039
+
**[:top: Scroll to Top](#javascript-interview-questions)**
1040
+
1041
+
### 70. Different ways to access object properties in javascript
1042
+
**Dot notation** - It uses dot (.) to access the object properties.
1043
+
```js
1044
+
object.propertyName
1045
+
```
1046
+
**Bracket notation** - It uses bracket "[ ]" to access the object properties.
1047
+
```js
1048
+
object[propertyName]
1049
+
```
1050
+
**Object destructuring** - It creates variables that correspond to the object properties.
0 commit comments