JavaScript  Revision Part 03

JavaScript Revision Part 03

Arrays

Arrays in JavaScript can store different types of data. They are basically a collection of values

Prototypes

Prototypes are the mechanism by which JavaScript objects inherit features from one another. In this article, we explain what a prototype is, how prototype chains work, and how a prototype for an object can be set.

Prototypical Inheritance

Prototypical Inheritance means all the objects of the same type will have access to all the functions and methods in the prototype of the object

Prototypical Inheritance vs Normal Class-Based inheritance

The difference is that normal inheritance is class-based.That means we need to have a class and an object But this is not the case with prototypical inheritance

Note: It is a bad practice to add methods to the prototype other than those which are present by default

forEach loop

This is a special loop which can be used only with array objects

var array=[1,2,3,4]

array.forEach(callback)

The callback passed will be called on every element of the array.

for-of loop

example: for(let bubble of bubbles){ //perform the operation } Which is read as : for every bubble of the bubbles array bubbles array consists of many bubbles

for-in loops

for in-loops are used to get the key-value pair when we use for in an array the key are the indices.The indices maybe iterated in a random order for(let key in array)