In python _ is used as a throwaway variable. Is there an idiomatic accepted name in javascript?
3 Answers
Rigth now, you can use array destructuring, no need for a var.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
For example:
[,b] = [1,2]; console.log(b); will output :
2 And the value 1 won't be assigned to any unused var.
Comments
There isn't an accepted throwaway variable naming in JavaScript like in Python.
Although, generally in the software engineering world, engineers tend to call those variables:
dummy, temp, trash, black_hole, garbage.
Use these variable namings or whatever name that will imply to the engineer reading your code that these variables have no specific use.
With that in mind, I would strongly not recommend using signs such as below as a throwaway variable:
_, $
Unless there is an explicit convention like in Python, don't use these signs as a throwaway variable, otherwise, it may interfere with other naming conventions and libraries in other languages, like the underscore and the jQuery libraries in JS.
And of course, if you find a specific use for that variable later on, make sure to rename it.
Comments
Generally, you will declare the signature of a function as an array. Simply omit one of them
const foo = (bar,baz,) => bar+baz; foo(3,4,5) // → 7 This obviously works as long as the declaration of function argument is the last one; unlike this answer, which is valid for already-declared variables embedded in arrays. This:
const foo = (, bar,baz) => bar+baz; will fail with:
Uncaught SyntaxError: expected expression, got ',' You can hack your way into this using any expression. However, you'll need to use the self same expression in every invocation
const quux = ([], bar,baz) => bar+baz; quux(42,3,4); // → Uncaught TypeError: (destructured parameter) is not iterable quux([],3,4); // → 7 That constant can be anything, so you can as well call it "dummy", but you will still have to repeat in every invocation.
dummyor something else.