Skip to main content

Posts

Showing posts from June, 2020

SIMPLE TASKS

HOISTING console.log(b); var b = 100; console.log(b); undefined 100 function hoist() { console.log( a,b ); a = 20; var b = 100; console.log( a,b ); } hoist();   console.log(a); console.log( window.a ); console.log(b) Error FUNCTION function myfun ( a,b ) {   console.log("hi");   if(a==10)   {     return a-b;   }   console.log( a + b );   return a+b ;   console.log("hello"); } a1 = myfun (10,20);   console.log( a1 );   b1 = myfun (20,10);   console.log( b1 ); a1 : hi -10 b1: hi 30 30 var m1 = 10; m1 = 20; function f1(m1) { if(m1 == 10) {   m1 = 20;    return 30; } if(m1 == 11) {   return; } return 30; console.log(m1); } m1 = f1(10); console.log(m1); m1 = f1(11); console.log(m1); m1 = f1(20); console.log(m1); 30 undefined 30

HOISTING

  HOISTING Variables” and “ function” declarations are moved to the top of their scope before code execution. Variables are hosted and not their values Only the normal function will be hoisted not the anonymous,IIFE and Arrow Function will be hoisted Properties are not hoisted PROPERTY  Any variable declared globally  become property of window variable declared without keyword variable declared with keyword var except function scope var console . log ( a )   // Error a not defined console . log ( a );  // undefined --> var a is hoisted not value var   a  =  20 ; console . log ( a , b )  // Error --->property b can't hoist var   a  =  20 ; b  =  40 ; var   a  = add ( 2 , 5 )  // Error console . log ( a ) var   a  = add ( 2 , 5 )  // 7 function add hoist console . ...

DATA COMPARISON OF ARRAY & OBJECT

DATA COMPARISON For Primitive Data Types we do usual comparisons To compare two array JSON.stringify(arr1)= = JSON.stringify(arr2) To compare Object function   objcomparison ( obj1 ,  obj2 ) {      var   arr1  =  Object . keys ( obj1 )      var   arr2  =  Object . keys ( obj2 )      var   count  =  0      if  ( arr1 . length  ==  arr2 . length ) {          for  ( i  =  0 ;  i  <  arr2 . length ;  i ++) {              //if(obj1.(arr1[i])==obj2.(arr1[i]))              if  ( obj1 [ arr1 [ i ]] ==  obj2 [ arr1 [ i ]])                ...