Something Like that:
Arguments
What is Arguments in javascript
The parameters you pass to a function
(Javascript gives you a keyword of the same name which contains them all)
For that you need to create first html code.
HTML
<p id="demo1"></p> <p id="demo2"></p> <p id="demo3"></p> <p id="demo4"></p> <p id="demo5"></p> <p id="demo6"></p> <p id="demo7"></p>
After that add this JS code.
JS
function greet(firstname, lastname, lang, ...other){ // ...other add extra value on parameters lang = lang || 'en'; if(arguments.length === 0){ document.getElementById("demo1").innerHTML = 'Missing parameters!'; document.getElementById("demo2").innerHTML = '-------'; return; } document.getElementById("demo2").innerHTML = firstname; document.getElementById("demo3").innerHTML = lastname; document.getElementById("demo4").innerHTML = lang; document.getElementById("demo5").innerHTML = arguments; //default variable of Javascript document.getElementById("demo6").innerHTML = 'arg 0: ' + arguments[0]; document.getElementById("demo7").innerHTML = '-------'; } greet(); greet('John'); greet('John', 'Deo'); greet('John', 'Deo', 'es', '111', 'my');
[codepen_embed height=”265″ theme_id=”0″ slug_hash=”PKmKxm” default_tab=”result” user=”pradeepanvi”]See the Pen Arguments in javascript by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]
Now you can see
Missing parameters!
John
Deo
es
[object Arguments]
arg 0: John
——-