Skip to main content


Showing posts with the label Js

Making Arrow in Javascript - ES 6

Arrow function aka fat arrrow was intorduced in ES6 as a new syntax for writing Javascript function.This is the most popular and highly used ES6 feature. Source Ponyfoo
What is Arrow function? Arrow functions provide a different way of creating functions in JavaScript. Besides a shorter syntax, they offer advantages when it comes to keeping the scope of the this keyword. What I meant by this line is, unlike other functions, the value of this inside arrow functions is not dependent on how they are invoked or how they are defined.It depends only on its enclosing context.
// ES5 - function declaration function callMe(name){              console.log(name);  }
which you could also write as:  // ES5 - function expression
const callMe = function(name) {         console.log(name);
becomes:  // ES6
const callMe = (name) => {              console.log(name);  }
Important Uses:When having no arguments, you have to use empty parentheses in the function declaration:
const callMe = () => {

How to Spread in Javascript - ES 6

Spread syntax was introduced as part of Javascript in the ES2015/ECMAS-6.

This allows iterable likes array, object or string to get expanded.

Spread can be used in following ways:
in array : [...iterableArray, 3 , 'four', 5]
in object : {...iterableObj}

The spread operator is very useful for concat, copying,apply, expanding, math operations,etc in array and objects. Let discuss each in detail.

var arr1 = [1,2,3];
var arr2 = [4,5,6];

without spread
var concatenatedArray = arr1.concat(arr2); // [1,2,3,4,5,6]

with spread
var concatenatedArray = [...arr1, ...arr2 ] // [1,2,3,4,5,6]

var arr1 = [1,2,3];
var arr2 = [...arr1];
console.log(arr2); // [1,2,3,4]
console.log(arr1); // [1,2,3]

Replacement for apply
var add = (a,b,c) => a+b+c;
var arr1 = [1,2,3];
add(...arr1); // replacing add.apply(null,arr1);

Expanding array
var programming = ["Java", "NodeJs", "Python"];
var subjects = ["Physics", ...programmi…

Javascript Interview Question and Answer - 3

In this post, I have discussed 5 basic javascript question and answer that is mostly asked in the interviews. Most of the time interviewer starts the interview with some of these basic questions.
So here we have

Q1. What is the difference between == and ===?

Solution : When we want to test the equality of two values(LHS and RHS), we use == or ===.
== is basically used to check if the two values are equal or not,and we are not considering their datatype. e.g.
if we check

5 == "5"   // true as values are equal
undefined = null   //  true as both represents NO VALUE

In case of ===, we not only consider the values but the datatype as well.e.g.

5 === "5"   // false as though values are equal but datatypes are different


undefined === null  //  false, as datatype of undefined and null is undefined and object respectively

It is highly recommended to use === in the programming as we get very unexpected results out of ==. e.g.

false == 0   // true
false == "false&qu…

Javascript Interview Question and Answer - 1





var Person = {
     name: 'Alex',
     age : 40,
    password : 'abc',
    x : {
       name : 'Chris',
       password: 'abcd',
       y : {
          name : 'Mike',
          password: 'abcd',

Before we …

Difference between undefined and null


The difference between undefined and null.



You can also call this NO VALUE as void or empty.



Now lets check each one of them.First lets talk about undefined.


1.   var foo;
2.   console.log(foo);   // undefined

Also when we try to access a variable before its initialis…

Difference between var, let and const

var, let and const in Javascript
 Variable can be declared in three ways: varletconstvar variables are function-wide scoped. Let's understand this with an example,    if(true){
let see with another example,
1.  function helloWorld(){      var x = 5;
2.     function abc(){
4.     }
5.     abc();
7. }
One of the famous example/question discussed in the interviews is following
2.                console.log(i);
3.       }