How to create a function with optional parameter in javascript
Hi, and welcome. I know you think this is a very easy issue right? You are supposed to know, don't worry we all have been there and we thought of the same thing. When you declare a function in JavaScript you provide the parameters that the function will need whenever its called. Maybe the parameter is used to to do something within the function maybe not. For the case of the situations where the function is called and no functions are defined there must be a way to overcome this scenario, which is what am going to show you THE SCENERIO // index.js //declaring a function const sayHi = ( name ) => { console . log ( 'Hi ' + name ); } //call the function sayHi (); // the output is going to be // Hi undefined 1. CHECK FOR THE PARAMETER BEFORE YOU USE ...