please dont rip this site

function Statement

See Also

Declares a new function. See also Function Object
function name([argument1 [, argument2 [, ...argumentn]]]) {    statements }
var name = function ( arguments ) stmt
var name = new Function ( arguments, stmt )

Arrow functions added in ECMAScript 2015:
var name = ( args ) => { stmt }

A "concise" body is assumed, where the expression is returned as if the body were { return expr }
var name = ( args ) => expr

Arrow functions combine nicely with array methods which accept a funtion. E.g.

var arr = [5, 6, 13, 0, 1, 18, 23];
var sum = arr.reduce((a, b) => a + b); //66
var even = arr.filter(v => v % 2 == 0); //[ 6, 0, 18]
var double = => v * 2); // [10, 12, 26, 0, 2, 36, 46]

and can produce cleaner promise chains

promise.then(a => {
// ...
}).then(b => {
// ...

They are the shortest way to provide an anonymous function:

setTimeout( () => {
  console.log('I happen sooner');
  setTimeout( () => {
    // deeper code
    console.log('I happen later');
  }, 1);
}, 1);

Note that arrow fuctions can be tricky:

Comma operator form (0, name()) This method of calling a function switches this from the local to the global this object. This may be useful because if you you have to know the name of the global object. And depending on the environment, it might not be windows. E.g. Javascript running on a server, node, embedded, whatever. This pattern is supported in order to be able to process mutiple assignments in the for command: for (i=0, j=10; i < 10; i++,j--),console

var x = "xGlobalFromWindow";
var obj = {
  x: "xLocalFromObject",
  getMyX: function() {
    return this.x;
console.log("(0, obj.getMyX)(): " + (0, obj.getMyX)() ); 
//"(0, obj.getMyX)(): xGlobalFromWindow"
console.log("obj.getMyX(): " + obj.getMyX() );
//"obj.getMyX(): xLocalFromObject"

The function statement syntax has the following parts:

Part Description
name The name of the function.
argument1...argumentn An optional, comma-separated list of arguments the function understands.
statements One or more JScript statements.
Use the function statement to declare a function for later use. The code contained in statements is not executed until the function is called from elsewhere in the script.

© 1997 by Microsoft Corporation. All rights reserved.

See also:

file: /Techref/inet/iis/jscript/htm/js756.htm, 6KB, , updated: 2020/3/14 12:21, local time: 2024/6/24 23:45,

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF=""> function Statement</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.

Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

  PICList 2024 contributors:
o List host: MIT, Site host, Top posters @none found
- Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.

Welcome to!