当前位置:网站首页>The JS method parameter passed a number beginning with 0. A magical problem occurred and bothered me for a long time

The JS method parameter passed a number beginning with 0. A magical problem occurred and bothered me for a long time

2022-06-24 20:34:00 zhanyd

Today I came across a magical problem , Make a special note of , It's very simple , Blame me for being too young ...

Here's the thing , One js Method to pass in a number , There is no problem at ordinary times , A simple example :

//  Defined function 
function logNum(num) {
    
  console.log(num)
}

//  Call function 
logNum(123)

 Output results :123

 Insert picture description here
That's no problem, right ?

Today I passed in a special number :0123, Something magical happened :
 Insert picture description here
How to become 83 了 ???

Does this figure have a special meaning ? It can't be said like that ?

Try another number :
 Insert picture description here
It's hard to understand !

later , Finally I found the same problem on the Internet :
 Insert picture description here
The answers are as follows :
 Insert picture description here

original 0 The first number is octal !

Use octal calculator to calculate 0123 Converting to decimal is really 83 Well !
 Insert picture description here

Empathy , Hexadecimal numbers are in 0x At the beginning :
 Insert picture description here

I'm so young !

原网站

版权声明
本文为[zhanyd]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202211327028933.html