Javascript arguments name list?

Like i for index as saw in examples. But other like w? or b? c? what stands for? A list for it?

function(i){//do something}

Thanks!

I don’t know of a formal list but the letters which come to mind are:
i - iterator
e - error
x - often used for delegates such as in a lambda

for the most part, i try to stay away from single characters.

1 Like

You can call it anything you want:

function myFunction(i) {
  console.log(i);
}
var i = 127;
myFunction(i);

The above will print out the number 127 to the screen.

So does this:

function myFunction(x) {
  console.log(x);
}
var i = 127;
myFunction(i);

And so does this:

function myFunction(elephantPajamas) {
  console.log(elephantPajamas);
}
var i = 127;
myFunction(i);

You can call the variable whatever you want. And this is an important concept - the variable inside the function is a different copy of the variable. (This gets a little more complicated with reference types like objects and arrays but lets put that aside for the moment.)

So, when I pass the variable in with myFunction(i);, it is not passing in the name i, just the value held in it 127, as the first (and in this case only) parameter. The function gets that value - function myFunction(elephantPajamas) { - it sees that I am sending in a first parameter and it sees that I want to call it “elephantPajamas”. It doesn’t know and doesn’t care that it used to be called “i”. This is it’s own clone.

If you’re asking why call it i? It can be called anything you want that is a valid JS variable name. Personally, I’d rather have a longer name so when I read it, I know exactly what it is. Even so, it is common to use i as a variable in loops (like for). Presumably that stands for “index”. In inner loops you might continue with j and k. Sometimes I use single letter variable names in small call back functions in prototype methods, where it is clear what it is from context. But other than that, I don’t like single character names.

1 Like

You know a lot! Thanks.

I’m learning too, I’m just farther down the path. Just keep working, you’ll get there.