Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

4. Function() > Redefining Function Parameters

Redefining Function Parameters

A function’s parameters can be redefined inside the function either directly, or by using the arguments array. Take a look at the code below.

Live Code

<!DOCTYPE html><html lang="en"><body><script>

var foo = false;
var bar = false;

var myFunction = function(foo, bar) {
   arguments[0] = true;
   bar = true;
   console.log(arguments[0], bar); // logs true true
}

myFunction();

</script></body></html>

Notice that I can redefine the value of the bar parameter using the arguments index or by directly reassigning a new value to the parameter.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint