assign value and display values are not same in javascript [duplicate] - javascript

This question already has answers here:
Number with leading zero in JavaScript
(3 answers)
Closed 2 years ago.
Have some doubts about the javascript. when I try to console
a = 021
console.log(a) // 17
why it is changing and how to store the exact value in the variable

Because with leading zero it's a octal-number so 21 is 2*8+1 = 16.
But when you print it out it's in decimal.

Related

Split Array Object Value in javascript [duplicate]

This question already has answers here:
Javascript How to get first three characters of a string
(2 answers)
Keep only first n characters in a string?
(7 answers)
Closed 7 days ago.
I'm confused where I want to split the correspondence_code value like in the image below : let say I want to get just the first 5 digits like 16020 it is possible just getting the first 5 value? Thanks in advance
var result = objt['psgc'].filter(obj => {
return obj.geographic_level === "province"
})
// I want to split the value result -> correspondence_code with only first 5 digits

Why is 76561198272848927 === 76561198272848930 true? [duplicate]

This question already has answers here:
Why are two different numbers equal in JavaScript?
(4 answers)
What is JavaScript's highest integer value that a number can go to without losing precision?
(21 answers)
Closed 2 years ago.
I currently try my best with the SteamAPI, for that I need the Profile-IDs. I tried out with my own, but somehow js changes the id.
EG:
https://imgur.com/a/83Yu6Cd
https://imgur.com/a/CRHtxnj
My ID is 76561198272848927, but JS somehow always change the last two digits from 27 to 30. Why? And how do I fix this?

Javascript Leading 0 on Integers Wrong Value [duplicate]

This question already has answers here:
Javascript 0 in beginning of number
(3 answers)
Closed 5 years ago.
Javascript leading 0 on integers getting wrong value on console.log.
Why I am getting like this ?
Code:
console.log(456);
console.log(0456);
Output:
456
302
Because JS "translates" 0456 as an octal value, since it has a trailing zero and all its digits < 8.

can't declare var a = 023; in js [duplicate]

This question already has answers here:
Number with leading zero in JavaScript
(3 answers)
Closed 7 years ago.
I want to declare
var a = 0213;
document.write(a);
but it not work .when console.log(a); variable
different.
Numbers with a leading 0 are interpreted as octal (base 8).
Octal 0213 == decimal 139.
If you need the value 213 (decimal), leave off the leading 0.

Why does "10" > "9" = false? [duplicate]

This question already has answers here:
Why is one string greater than the other when comparing strings in JavaScript?
(5 answers)
Javascript string/integer comparisons
(9 answers)
Closed 8 years ago.
Is this a failure in JavaScript's attempt to convert them to numbers? If so, what numbers are they being converted to? Or what is the logic behind the string 10 being less than the string 9?
It's comparing the strings "alphabetically", and 1 comes before 9 in the character "alphabet".

Categories