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
Before rest parameters existed, to get all the arguments in a function we used arguments which is an array-likeobject.
1294
+
1295
+
function someFunction() {
1296
+
return arguments;
1297
+
}
1298
+
1299
+
someFunction("joykare", 100, false);
1300
+
1301
+
someFunction returns the arguments and their indexes, [Arguments] { '0': 'joykare', '1': 100, '2': false }.
1302
+
1303
+
The downside of using the arguments keyword is that, it returns an array-like object; this means you essentially cannot perform any array-methods like; Array.filer, Array.map. Another pitfall, is that we cannot use arguments in arrow functions.
1304
+
1305
+
1306
+
#Spread operator: allows iterables( arrays / objects / strings ) to be expanded into single arguments/elements.
1307
+
1308
+
The spread operator allows us to expand elements.
1309
+
1310
+
you are expanding a single variable into more:
1311
+
1312
+
var params = [ "hello", true, 7 ];
1313
+
var other = [ 1, 2, ...params ]; // other => [1,2,"hello", true, 7]
1314
+
Here, ...params spreads so as to assing all of its elements to other
1315
+
1316
+
Internally javaScript does following
1317
+
1318
+
var other = [1, 2].concat(params);
1319
+
1320
+
const arr = ["Joy", "Wangari", "Warugu"];
1321
+
const newArr = ["joykare", ...arr];
1322
+
1323
+
const myNames = [...arr, "joykare"];
1324
+
1325
+
We can use the spread operator to copy an array.
1326
+
1327
+
const arr = [1, 2, 3];
1328
+
const arr2 = [...arr];
1329
+
1330
+
## Explain how prototypal inheritance works
1331
+
This is an extremely common JavaScript interview question. All JavaScript objects have a prototype property, that is a reference to another object. When a property is accessed on an object and if the property is not found on that object, the JavaScript engine looks at the object's prototype, and the prototype's prototype and so on, until it finds the property defined on one of the prototypes or until it reaches the end of the prototype chain. This behavior simulates classical inheritance, but it is really more of delegation than inheritance.
0 commit comments