Skip to content
Akin C edited this page Apr 15, 2018 · 8 revisions

Welcome to the Javascript-save-arguments-into-a-variable- wiki!

This repository is part of a larger project!

◀️ PREVIOUS PROJECT| NEXT PROJECT ▶️


The Javascript object arguments should work function-scoped oriented. Here follows an example:

function g()
{
	function f()
        {
		for(var i = 0; i < arguments.length; i++)
                {
			console.log(arguments[i]);
		}
	}
        
        //Calling f
        f();
}

//Outputs: undefined
g(1,2,3,4,5);

By analysing the listing above, it should be said that arguments in the nested function f works only for this function. This should be the reason why g(1,2,3,4,5) outputs undefined . To output the arguments (1,2,3,4,5) with the object arguments the code could look like as follows:

function g()
{
    //Object "arguments" here belongs to the function g()
    for(var i = 0; i < arguments.length; i++)
    {
    	console.log(arguments[i]);
    }

    function f()
    {
        //Object arguments here belongs to the function f()
	for(var i = 0; i < arguments.length; i++)
        {
		console.log(arguments[i]);
	}
    }

    f();

}

//Outputs: 1,2,3,4 and 5
g(1,2,3,4,5);

📕 It should be possible to give the arguments of g to the function f by saving g's object arguments to a variable as the following example should show:

function g()
{
	var parameters = arguments;

	function f()
        {
		for(var i = 0; i < parameters.length; i++)
                {
			console.log(parameters[i]);
		}
	}

	f();
}

//Outputs: 1,2,3,4 and 5
g(1,2,3,4,5);

Again, the last listing should work, because Javascript should be function-scoped.

Content

The user interaction part could look like the content as seen below by starting "index.html" in a web browser and interacting with its features.

ERROR: No image found!

  • 🅱️ utton "<<" should change to the previous image
  • 🅱️ utton ">>" should change to the next image

To use the project just download the files and execute "index.html". Note that all files(folder "wiki_images" excluded) should be placed in the same folder so that the functionality of the code is guaranteed.

Clone this wiki locally