Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent of python's _ in javascript?

In python _ is used as a throwaway variable. Is there an idiomatic accepted name in javascript?

like image 846
blueFast Avatar asked Jan 06 '16 08:01

blueFast


People also ask

What is this _ in JavaScript?

What is this? In JavaScript, the this keyword refers to an object. Which object depends on how this is being invoked (used or called). The this keyword refers to different objects depending on how it is used: In an object method, this refers to the object.

Is there a Python equivalent for JavaScript?

It is not Javascript code! Instead, you will find Python code in a script of type "text/python". Brython is designed to replace Javascript as the scripting language for the Web.

What is Python pass in JavaScript?

Python pass Statement The pass statement is used as a placeholder for future code. When the pass statement is executed, nothing happens, but you avoid getting an error when empty code is not allowed.

What is the equivalent of a list in JavaScript?

The closest equivalent in all cases of what is passed to list() would be using the spread syntax from ES6. For older versions of JavaScript, you can use string. split('') for a character array.


1 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.

like image 133
Maxime Ancelin Avatar answered Sep 25 '22 08:09

Maxime Ancelin