Why the output of this program is wrong? 😵😵Help. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why the output of this program is wrong? 😵😵Help.

I was writing a program. I created an array of numbers. I used to output first value of array in console.log. But the output is wrong. Can you dicuss me why the output value is wrong. The code is let n = [0234]; console.log(n[0]); //156 (Sorry for bad English) https://code.sololearn.com/WPA0V0emne0K/?ref=app

27th Jun 2020, 11:18 AM
Varinder Singh
Varinder Singh - avatar
1 Answer
+ 3
If you had put commas (,) into your array, it would have output 0. Because you forgot the commas, 0234 leads with a 0, which denotes an octal number. 234 is 2 x (8 x 8) + 3 x 8 + 4 = 156
27th Jun 2020, 11:34 AM
Russ
Russ - avatar