Some basic concept of JavaScript

Md. Akash Hossain
3 min readMay 8, 2021

1. Falsy value

The term Truthy and Falsy value are broadly used in condition checking statements. If the value of something has empty, zero(0) then it is considered a false value.

const a = ‘’; //empty stringconst b = 0; // numberconst c = false; //Boolean valueif( a || b || c){//can’t execute statements cause a, b and c all are falsy and doesn’t satisfy condition}

2. Truthy value

If the value of something has empty, zero(0) then it is considered a false value otherwise it is true.

const a = ‘ hi’; //empty stringconst b = 3; // numberconst c = true; //Boolean valueif( a && b && c){//executes statements cause a, b and c all are truthy and satisfy condition}

3. Null value

The null value represents intentional missing any object value;

const a = “”;console.log(a); // output is null

4. Undefined value

In our coding, we all might get noticed the ‘undefined’ word. It is mainly occurred when we declare a variable and want to use it but not initialized it.

const a;console.log(a); // output is undefineda= “hi”;console.log(a); // output “hi”

5. “==” double equal

Most of the programming language double equal is used to compare two variables or others whether they are equal or not.

const a = 5;const array = [1,2,3,4,5]const b = array.length;if (a == b){console.log(“both a and b are equal”); // execute while running}

6. “===” triple equal

Triple equal is used to compare two variables or others whether they are equal or not and their data type as well.

const a = “5”; // stringconst array = [1,2,3,4,5]const b = array.length;if (a === b){console.log(“both a and b are equal with data type”); // doesn’t execute while running}

7. Bind method

If we want to use a function of an object to another object then bind may help us. After binding one object to another it returns a function that works on which object is bound.

syntax: object1.methodNameOfObject1.bind(object2)

const object1= {const name = “rohim”displayName: function(name){return this.name+ “ ”+name; 
}}
const object2= {const name = “korim”}const func = object1.displayName.bind(object2);console.log(func(“jalil”)); // output korim jalil

8. Call method

If we want to use a function of an object to another object then the call method also helps us. After calling one object to another it returns the desired output of that first object method returns. Here you can use the method directly by giving parameters using a comma in between them.

syntax: object1.methodNameOfObject1.call(object2, p1, p2,p3,…,pn)

p=parameter

const object1= {const name = “rohim”;displayName: function(name1, name2){return this.name+ “ ”+name1+ “ ”+name2; 
}}
const object2= {const name = “korim”}const concatName= object1.displayName.call(object2, kuddus, john);console.log(concatName); // output korim kuddus john

9. Apply method

If we want to use a function of an object to another object then the call method also helps us. After calling one object to another it returns the desired output of that first object method returns. Here you can use the method directly by giving parameters as an array.

syntax: object1.methodNameOfObject1.apply(object2, [p1, p2,p3,…,pn])

p=parameter

const object1= {const name = “rohim”;displayName: function(name1, name2){return this.name+ “ ”+name1+ “ ”+name2; }}const object2= {const name = “korim”}const concatName= object1.displayName.call(object2,[ kuddus, john]);console.log(concatName); // output korim kuddus john

10. Arrow function

The Arrow function is like a normal function with a different declaration.

syntax: const x = (p1, p2, p3,…,pn) => { //function body}

p=parameter and returned value is stored in x;

const x= () =>{ 
console.log(“arrow function with empty parameter”);}
const y = (name) =>{
console.log(“arrow function with single parameter”, name);}
const z= (name1, name2) =>{
console.log(“arrow function with multiple parameters”, name1, name2);}

--

--