JavaScript Core Concepts

Truthy Falsy :

As every data has a type, therefore every each value has an inherit Boolean value. That is either truthy or falsy.

Some falsy values are: 0,false, “”, null, undefined, NaN..

Other than these values every other things are truthy..

Null vs undefined:

In javaScript undefined is a data type but null is an object. Undefined means a variable is declared but never assigned a value. Where null is itself an assigned value. One can add null to any other variable.

Double equal (==):

There is sometime confusions about == and === . So what does it means to write ==?

Comparison is one of the core concepts of programming logic. We can compare if two values are equal or not . We use == to compare two values not mentioning its data type in js. For example , if we write 2==’2’ it will be true. That is == only compares the values not the type

Triple equal (===):

=== is used when we compare two values along with their data types. Lets say 2===’2’ will return false but 2===2 will return true as they are same in both value and data type.

JavaScript Scope:

JavaScript has function scope. Each function creates a new scope. The scope in the accessible area of any javaScript function. Variable defined with let / const is only accessible by this specific scope. The variable or the function declared in a scope in local

JavaScript supports two kind of scopes:


A closure is the combination of a function and the lexical environment within which that function was declared. i.e, It is an inner function that has access to the outer or enclosing function’s variables. The closure has three scope chains

Block Scope:

A block scope is the area within if, switch conditions or for and while loops. whenever it is a {curly brackets}, it is a block. In ES6, const and let keywords allow developers to declare variables in the block scope, which means those variables exist only within the corresponding block.

Calback Function:

A callback function is a function passed into another function as an argument. This function is invoked inside the outer function to complete an action. The callbacks are needed because javascript is an event driven language. That means instead of waiting for a response javascript will keep executing while listening for other events. Let’s take an example with the first function invoking an API call(simulated by setTimeout) and the next function which logs the message.

JavaScript Encapsulation:

The JavaScript Encapsulation is a process of binding the data wwith the functions acting on that data. It allows us to control the data and validate it. To achieve an encapsulation in JavaScript: -

Encapsulation includes the idea that the data of an object should not be directly exposed. Instead, callers that want to achieve a given result are coaxed into proper usage by invoking methods (rather than accessing the data directly).

Private Variables:

In many object-oriented programming languages, there is a way to limit the visibility of a variable from outside its scope. In other words, some programming languages allow variables to only be accessible by the object that “owns” it. To be more technical, a private variable is only visible to the current class. It is not accessible in the global scope or to any of its subclasses. For example, we can do this in Java (and most other programming languages) by using the private keyword when we declare a variable. Attempting to access the private variable outside of the class that owns it will throw an error.

Front End React JS Developer