In JavaScript (x, x1, x2, …, xn) always returns xn.
In Python this code is called tuple and it returns different values.
My question is what is the purpose of this code in JavaScript?
Do you have some practical example?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The comma operator evaluates every operand but only returns the result of the last evaluation. It can be used to initialize multiple variable in a for loop.
Edit: As pointed out in the comments, this isn’t a true example of the comma operator, this is just the
var. You can see this page for actual examples.