Learn More About Js

Yeasin Hossain
2 min readMay 8, 2021

Truthy and Falsy values

in condition will fill if the argument true, if we use ‘if()’ condition, if the condition is true then execute first option else go for ‘else’ section. in javascript has some value which always values is false. this value is always false, 0, -0, “”, null, undefined, NaN, and more. expect this everything is true here is some example “0”, “false”, [], {},function(){}.

Null Vs Undefined

null and undefined twice are false values. undefined mean, you declare a variable but value not yet defined. that’s means is undefined. and null means there was a value but somehow you remove the value and defined null, that’s this is empty.

// undefined
let num;
// null
let num = 1;
num = null;

double equal (==) vs triple equal (===)

double equal (==)is compared with only data, it’s may not check data type.

const num1 = 1;
const num2 = "1";
const result = num1 == num2 ? 'true' : 'false';
output:- true

in triple equal (===), it will also check data type. data same but type not same, it returns false.

const num1 = 1;
const num2 = "1";
const result = num1 === num2 ? 'true' : 'false';
output:- false

Scope, block scope,

you declare a variable inside of the function, this variable is available only inside of the function. you can’t access out of function. rather than you declare a variable outside of the function and this variable available everywhere. this call scoping. in js has a global scope and private scope. each independent variable is global. and inside of curly braces, the variable is private and available only in this block.

// global scope
const name = 'yeasin';
const fun = ()=>{// block scopeconst testVar = 'Test';
}

Closure

the closure gives you to access the closest environment. normally global variable can access from anywhere. but you have a nested function. by closer, you can access a closet variable by the closure

const testFun = ()=>{const name = 'Yeasin';const nestedFun = ()=>{ // closure
console.log(name);
}
}

private variable

you want to nobody can access this variable or method, it has credentials. you can make it private by using #.

class PrivateVariable {#myInformation = 'Card Information'
}

setTimeout

setTimeout is an Asynchronous operation. setTimeout take two arguments, first callback function and time. after that time callback function will execute.setTimeout call only once.

setTimeout(()=>console.log('HI'),300);

setInterval

setInterval also likes setTimeout, but setInterval calls continuously. after reach time, it will count start again.

setInterval(()=>console.log('HI'),300)

API

API means application programming interface. which helps us communicate with the server. throw API we can send data to the server and receive data from the server. in javascript, we use to fetch call apis.

GET Method

when want receives data from the server, this time we send get request to the server. and the server gives us data. to communicate with the server, have some rules. which must be required.

POST Method

for saving data to the server throw APIs we have to use the POST method. POST method means we sending some data, the server has to recive.

--

--

Yeasin Hossain
0 Followers

A full-stack developer and learner.