# DAY21 - JavaScript 25. 數字轉字串的方法 - toString() - 宣告變數為 number 型別。 ``` let b = 1; console.log(typeof b); // 回傳: number ``` ### toString(),讓型別轉型 string - 作法: ``` // b 轉型別成 string 步驟: b = b.toString(); console.log(typeof b); - string // 驗證: console.log(b + 100); - 1100 ``` ### 補充, toString() 與 parseInt() 帶入的方法不太一樣 - ex,parseInt: ``` // parseInt()內會包變數 let a = '1'; a = parseInt(a); ``` - ex,toString(): ``` // toString 的寫法,會先用一個.toString() 但變數是寫在.之前 let b = 1; b = b.toString(); ``` ###### tags: `Re:0 前端工程師之路 - JavaScript 布林型態 篇章`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up