How to check if method parameter is passed in javascript

31 July 2022

Sometimes it is necessary to be sure that method parameter we are trying to comsume exists.

So, if parameter is not passed we can protect our code from failing with this simple single liner.

function doSomeStuff(isItPost) {
    isItPost = typeof isItPost !== 'undefined'? isItPost : false;
    console.log(isItPost);
}