Java Script CORE concept

Omar Faruq
3 min readMay 9, 2021

#Truthy and Falsy:
As nicely as a type, every price additionally has an inherent boolean value, normally recognized as both truthy or falsy. Some of the policies are a little weird so grasp the principles and impact on contrast helps when debugging JavaScript applications.

The following values are always false:

-false
- 0 (zero)
- ‘ — - ’ or ‘ — -’(empty string)
- null
- undefined
- NaN

Everything else is truthy. That includes:

  • '0' (a string containing a single zero)
    -'false' (a string containing the text “false”)
    -[] (an empty array)
    -{} (an empty object)
    -function(){} (an “empty” function)

#Null Vs. Undefined:

A null is an object and Undefined is a type itself.

Null indicates the absence of a value for a variable. and Undefined indicates the absence of the variable itself.

Null is converted to zero (0) while performing primitive operations. and Undefined is converted to NaN while performing primitive operations.

null is an empty or non-existent value. and undefined is a non-existent variable.

#Double equal (==) vs Triple equal (===):

Well in short: == inherently converts kind and === does no longer convert type.

Double Equals (==) assessments for fee equality only. It inherently does kind coercion. This capability that earlier than checking the values converts the sorts of the variables to fit every other.

On the different hand, Triple Equals (===) does now not function kind of coercion. It will confirm whether or not the variables being, in contrast, have each the identical fee AND the equal type.

OK — so let’s assist you higher apprehend the distinction via a few examples. For every of these, reflect on consideration on what the output of these statements will be.

#Closures, Encapsulation, Private:

Closures:
A closure is the mixture of a characteristic bundled collectively (enclosed) with references to its surrounding kingdom (the lexical environment). In different words, a closure offers you get right of entry to an outer function’s scope from an internal function. In JavaScript, closures are created each and every time a feature is created, at characteristic advent time.

Encapsulation:
JavaScript Encapsulation is a technique of binding the information (i.e. variables) with the features performing on that data. It permits us to manipulate the information and validate it. To gain an encapsulation in JavaScript: Use var keyword to make statistics contributors private.
Use setter strategies to set the information and getter strategies to get that data.

Private Variables:

JavaScript has had a lot of enhancements recently with new syntax and points being delivered all the time. But some matters do not change, the whole thing is nonetheless an object, exceedingly tons the whole lot can be altered at runtime and there is no idea of public/private properties. But there are some hints we can use to alternate some of this ourselves, in this submit I am going to seem to be at the numerical methods in which we can enforce non-public properties.

#Bind, Call, Apply:

bind: It binds the feature with furnished cost and context however it does no longer executes the function. To execute the feature you want to name the function.
call: It executes the feature with furnished context and parameter.
apply: It executes the feature with supplied context and parameter as an array.

#this keyword:

What is this?
In JavaScript, this keyword refers to the object that is presently executing the code. The brief model of what this evaluates to is as follows:

By default, this refers to the international object.
In a function, when now not in strict mode, this refers to the international object.
In a function, when in strict mode, this is undefined.
In an arrow function, this retains the cost of the enclosing lexical contexts.
In an object method, this refers to the object the technique used to be known as on.
In a constructor call, this is certain to the new object being constructed.
In a matching handler, this is certain of the factor on which the listener is placed.

#What is the DOM?

The DOM is a W3C (World Wide Web Consortium) standard.

The DOM defines a widespread for gaining access to documents:

“The W3C Document Object Model (DOM) is a platform and language-neutral interface that approves packages and scripts to dynamically get right of entry to and replace the content, structure, and fashion of a document.”

The W3C DOM general is separated into three exclusive parts:

— Core DOM — general mannequin for all report types
— XML DOM — widespread mannequin for XML documents
— HTML DOM — preferred mannequin for HTML archives

--

--