字符串轉換成數字

PHOTO EMBED

Thu Jun 23 2022 09:09:33 GMT+0000 (Coordinated Universal Time)

Saved by @Roy

// 常规逻辑
const num = parseInt("10");

console.log(num); // 10
console.log(typeof num); // "number";

// 优雅写法
const num = +"10";
console.log(num); //=> 10
console.log(typeof num); // "number"
console.log(+"10" === 10); // true;
content_copyCOPY