Five things you should know about JavaScript.

Primitive vs Reference:

In javascript, there are two types of data 1. Value types (primitive) 2. Reference types.

Value types: number, string, boolean, symbol, undefined and null are value types. Let's have an example:

In this example, variable (a) have value 5, when we set value (b = a) it only copies the value of the variable (a). They are completely independent of each other.

Reference types: object, function, array are reference. Let’s have an example:

What happened in this example? Well, in this example when we use an object that object is not stored in the variable (a). That object stored somewhere else in the memory and the address of that memory location stored inside the variable (a). So, when we copy (a) into (b) is the reference only copy. when we modify the object either (a) or (b) it changes immediately visible to other variables. So, primitives are copied by their values and objects are copied by their reference.

How does javascript work?

Let’s have a look at an example:

if we run this example code in the browser first of all js runtime engine read the code line by line but no function execute until we invoke or call a function. when a function call [called()] than the function will execute. In the first example, called() function will execute and inside the function say()will be executed next. Inside the say() function greeting() function will execute. Finally, called() function execution will be finished.

An enthusiast JavaScript and React developer.