+ 1

Python vs JavaScript: a = (1,2,3)

let a = (1,2,3); let a = (1,2,3); console.log(a); // 3 1. Anyone to explain how is it interpreted in JavaScript? Is it a multiple assignment to the same variable where only the last one are remains, and all previous values are dropped? In Python, it is a tuple. 2. Why are parentheses necessary (it does not run without them)? I know that it is a very simple question but I am a beginner in js. I have found it in a SL challenge and I would like to learn from this example.

21st Mar 2020, 7:28 AM
Prof. Dr. ZoltƔn Vass
3 Answers
+ 5
In JavaScript everything inside a () operator is treated first. But as there is no operation happening inside the brackets so all the programe do is to read the variables and reject them till the time end ")" is not reached. After that "a" is assigned the "calculated" value, which is nothing but the only non discarded value ("3" in this case)
21st Mar 2020, 7:34 AM
Arsenic
Arsenic - avatar
+ 3
怌ļ¼Øļ¼”ļ¼°ļ¼°ļ¼¹ ļ¼“ļ¼Æ ļ¼Øļ¼„ļ¼¬ļ¼°ć€ Thanks for your answer. Also this type of brackets converts it to an array?
21st Mar 2020, 7:44 AM
Prof. Dr. ZoltƔn Vass
0
怌ļ¼Øļ¼”ļ¼°ļ¼°ļ¼¹ ļ¼“ļ¼Æ ļ¼Øļ¼„ļ¼¬ļ¼°ć€ Ok! I have corrected brackets to parentheses in the original question.
21st Mar 2020, 2:58 PM
Prof. Dr. ZoltƔn Vass