Top 10 Important Things of JavaScript

1. Truthy and Falsy Values-

let num=12;if(num){console.log("true");}else{console.log("false");}
let num=0;if(num){console.log("true");}else{console.log("false");}

2. double equal (==) vs triple equal (===)-

let num1= 5;let num2= "5";if(num1==num2){  console.log("true");}else{  console.log("false");}
let num1=5;let num2= "5";if(num1===num2){  console.log("true");}else{  console.log("false");}

3. Scope-

function print(){  let text = "Hello World";}print();console.log(text)
function print(){let text = "Hello World";return text;}console.log(print())

4. Closure-

function watch(){ let count = 0;  return function(){     count++;     return count;   }}const clock1 = watch();console.log("I'm Clock 1 : ",clock1())console.log("I'm Clock 1 : ",clock1())console.log("I'm Clock 1 : ",clock1())const clock2 = watch();console.log("I'm Clock 2 : ",clock2())console.log("I'm Clock 2 : ",clock2())

5. bind() Method-

const obj1 = {  num1: 3,  num2: 4,  add: function(){    return this.num1+this.num2;  }}const obj2 = {  num1: 5,  num2: 10}const result = obj1.add.bind(obj2);console.log(result()); // 15

6. call() Method-

const obj1 = { num1: 3, num2: 4, result: null, add: function(){  this.result = this.num1+this.num2  return this.result;  }}const obj2 = {  num1: 5,  num2: 10,  result: null}obj1.add.call(obj2)console.log(obj2.result);
const obj1 = {result: null,add: function(n1,n2){this.result = n1+n2;return this.result;}}const obj2 = {result: null}obj1.add.call(obj2 , 15 , 20)console.log(obj2.result); // 35

7. apply() Method-

const obj1 = {result: null,add: function(n1,n2){this.result = n1+n2;return this.result;}}const obj2 = {result: null}obj1.add.apply(obj2 , [15,20] )console.log(obj2.result);

8. Asynchronous Javascript-

console.log(“Hello”);console.log(“World”);
setTimeout(function(){console.log("Hello");})console.log("World");

9. Recursion-

function countDown(number) {console.log(number);const newNumber = number - 1;if (newNumber > 0) {countDown(newNumber);}}countDown(10);

10. let const ( ES6 )-

let number = 6;
number = 3;
const number = 6;

Web Developer