轉換為數字更快的方式
轉換字串為數字是相當常見的。最簡單和快速的方式是使用 +
(加號)運算子來實現。(jsPerf)
var one = '1';
var numberOne = +one; // Number 1
你也可以使用 -
(減號)運算子將數字類型轉換成負數。
var one = '1';
var negativeNumberOne = -one; // Number -1
MEET THE NEW JSTIPS BOOK
You no longer need 10+ years of experience to get your dream job.
Use the 100 answers in this short book to boost your confidence and skills to ace the interviews at your favorite companies like Twitter, Google and Netflix.
GET THE BOOK NOW
MEET THE NEW JSTIPS BOOK
The book to ace the JavaScript Interview.
A short book with 100 answers designed to boost your knowledge and help you ace the technical interview within a few days.
GET THE BOOK NOW