当前位置:网站首页>JS auto increment and auto decrement (unary operator)

JS auto increment and auto decrement (unary operator)

2022-06-09 21:35:00 qq_ forty-six million three hundred and two thousand two hundre

Unary operator :
You can use + Number , take string -> number

let a = '123'
a = +a
console.log(a,typeof a) // 123 'number'

Self increasing :

let a = 1
console.log(a++)  //1 
console.log(`a=${a}`) //a=2 
let a = 1
console.log(++a) //2
console.log(`a=${a}`) //a=2 
let d = 20
d =d++
console.log(d)  //20

Self reduction :

let a = 3
console.log(a--); // 3
console.log(a) // 2

let b = 3
console.log(--b); // 2
console.log(b); //2
原网站

版权声明
本文为[qq_ forty-six million three hundred and two thousand two hundre]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206092059516570.html