Javascript - Argument

About

This page is about function arguments in javascript.

Snippet

the built-in arguments variable

The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5.

let fn = function() {
   console.log(arguments)
   console.log("First Argument: "+arguments[0]);
   console.log("All Arguments joined: "+Object.values(arguments).join(", "));
   console.log("The type is "+(typeof arguments))
   console.log("The class is "+arguments.constructor.name)
};

fn('arg1','arg2');

default

let fn = function(name="Foo") {console.log(`Hello ${name}`)};

fn();

Rest

It's also working with Rest argument

let fn = function(name="Foo",...rest) {console.log(`Hello ${name} and the rest ${rest}`)};

fn("Bar","Foo","Foobar");

Documentation / Reference





Discover More
How to create a Debounce Function in Javascript?

A debounce is a function that: will wrap a callback function willnot let the callback function execute for each event will let the callback function execute only when a certain amount of time...
Javascript - Apply

apply permits to call a function stored in a variable specifying: its execution context: this and its arguments eval A function that we will call with apply that: print the name property of...
What does Three points in Javascript? known as the Spread or Rest Operator

The ... three points may refer to: the spread operator. It 'expands' an array into its elements, or the rest parameter. It 'condenses' multiple elements into a single element You use it for object...



Share this page:
Follow us:
Task Runner