JavaScript default parameters


Since es6 its possible to include default function parameters just like other programing languages such as php do,
default parameters cut down the need to initially set default Parameters within the code as;

const vec function (x, y){

    if(typeof x == "undefined")

    x = 0;

if(typeof y == "undefined")

    y = 0;

    return {

        x, y

    }

}

now the above can be done in a more simple way , using default parameters as;


const vec function (x = 0, y = 0){
    return {

        x, y

    }

}
In either of the functions if you omit either of the Parameters your parameter will default to zero ie 0;

Comments

Popular posts from this blog

Open-graph meta data tags introdution

What is 'this.' keyword in JavaScript

How to create zip archives in nodejs

what is 'array.includes' function in JavaScript

How to build a twitter retweet bot using JavaScript