JavaScript Core Concept EveryOne Need to Know

JavaScript Hoisting

In this section I will discuss how to treat hoisting mechanisms in javascript. Before start at the first we can briefly understand what is hoisting

Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution.

This means that no matter where functions and variables are declared, they are moved to the top whether their scope is global or local.

Execution context hoisted variable decaleration only:

console.log(name); // Output: undefined

var name = ‘John Due.’;

Because javascript only hoisted our variable declaration not initialization.

Execution context hoisted function decaleration only:

hoist(); // executional context are not execute code first

function hoist() {

a = 20;

var b = 100;

}

First time creational phase create our declaration and hoist that top there scope like:

// hoist() = Reference

Truthy vs Falsy values in JavaScript

When you write an if/else statement in javascript, you expect to pass a value in the if() condition that is strictly boolean value which means either true or false. It could also be an expression that evaluates to one of these values as demonstrated below.

falsy :- false, ‘’, “”, 0, -0, NaN, null, undefined

truthy :- Everything else is true which is not above

if you use one of these values in the if/else condition block, you get the same treatment as true and false values.

Let’s see an Example:

Double Equals vs. Triple Equals

When we need to equally compare between two values then we use double (==) or Triple (===) but there are very different ways to test equality.

Triple Equals

When we use triple equal(===) for test equality we are testing strict equality in javascript. This means === check the equality both of data type and value are exactly what. See below an strict equality example

Double Equals

When we use double equal(==) for check loose equality. Double equal only check the value not check their data type. Lets see an example and clear your doubt double equal and triple equal.

JavaScript Scope:

In this section I will discuss what is scope in javascript.

scope

JavaScript Scope works in his own area. Scope determines the accessibility of these variables. When a variable is declared in a function then it’s called only the function scope that is not accessed outside of the function.

example:

Global scope

When a variable is declared outside a function the variable will become a global variable. Global variable has always global scope that means global context that is accessible from anywhere in our script and function.

Example:

Block scope

When we write any code inside curly braces {}. it will create block scope like a function, if/else for loop. Which variable and function we declare the block inside curly braces are not accessible outside the block scope.

JavaScript this Keyword

JavaScript this keyword basically refers to the object. It has different values. it depends on where it is used. See an example below.

  • In a method, this refers to the owner object.
  • Alone, this refers to the global object.
  • In a function, this refers to the global object.
  • In a function, in strict mode, this is undefined.
  • In an event, this refers to the element that received the event.
  • Methods like call(), and apply() can refer this to any object.

API

What is an API. API stand by (Application Programming Interface) When we browse an web application like facebook, youtube using mobile phone or computer the application sends some data to the server and sends a request for data to the server. Behind The scenes The server responds to our request and returns those data that the browser sends requests. Api has some methods for communicating with the server such as GET, POST.

GET Method

Get is the one of the most common and popular methods for requesting servers for specific resources like https://jsonplaceholder.typicode.com/posts

POST Method

Post method used to send data to the server to create/update a resource. This method is secured for use by password and payment process.

I am a hard working individual web developer with deep knowledge and proficiency in front-end technology

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store