DEV Community

Cover image for A Few JavaScript Advanced Concepts
Rakib Hasan Babu
Rakib Hasan Babu

Posted on

A Few JavaScript Advanced Concepts

Truthy and Falsy Value
Considering the boolean concept, the which value expression is true is considered as truthy value, and which value expression is false is called falsy value.

Null vs Undefined
In JavaScript, undefined is a type and null is a value. When a variable is declared, but no value is assigned, then it returns undefined. As null is a value, it can assign to a variable.

Double Equal (==) vs Triple Equal (===)
Both of the signs are comparison operators. The “==” is used to compare values, and “===” is used to compare both values and types.

Closure
Inside a function, if we return another function and if this function is called from outside, then the function creates a closure for the outside’s function calling. If another function calls the above function, then the above function creates another closure for this function call. The above function stored a reference for each function call. And that is closure. It works by reference. For every new function, it creates new closure and stores a new reference.

Bind, Call and Apply
When a method is defined in local scope, then it is accessible or usable only within the scope. But, if we want to use this method in another object, then we can use the method by calling the object and method like,
objectName.methodName.bind(newObject).
Here, objectName is where the method exists, the methodName is the name of the method, pass newObject as an argument where we want to bind the method.
If we directly call the method from the object, then we need the call() method.
objectName.methodName.call(newObject, argument1, argument2, ...)
In the call() method, we pass the object where we want to use the method, also pass the argument or arguments that are needed to the method.
The call() and apply() methods are mostly similar with just one difference. In the call() method we passed the object where we want to use and passed the argument/s that are needed in the object. There the arguments are separated by a comma (,), but in the apply() method, we wrap all the arguments within an array except the object name.

DOM
Document Object Model is shortly known as DOM. When a web page is reloaded, the browser creates a DOM of the page. And HTML DOM is considered as a tree of objects. JavaScript has the power to change any of the elements, attributes, CSS styles, or events.

API and Purpose of GET and POST API
API stands for Application Programming Interface, which is considered as middleware that connects two applications or software to pass data. GET is the method of extracting something from a server or something like a server. And POST is the method of posting or storing something on a server.

Event Bubble, Event Delegate, and Purpose of Event Bubble
JavaScript runs in the browser, as follows: when the browser gets clicked then it finds the area where it got clicked. The browser continues searching this process until it gets the clicked area. When it finds the clicked area then it checks if any event handler exists or not in the clicked area. If any event handler remains, then the browser triggers the event, after completing this the browser lifts up and checks if any other event remains or not. If it remains, then it triggers the event, and as like as it is lifting up and continues this process until it appears into the browser window. This process is like a bubble, And this event bubble system.

Top comments (0)