JavaScript Numbers & String 互動小技巧 | Compbrother Ltd

JavaScript Numbers & String 互動小技巧


Web Design Expert!

Compbrother  @ Web Design : JavaScript Numbers & String 互動小技巧

Publish Date: 2021-12-28

Article Type: Web Design

數字(Numbers)和字串 (String)之間,會因應一些條件的不同而processing 的處理效果亦會不同。

首先,最簡單的兩個數字相加:
let a = 5;
let b = 8;
let c = a + b; (c的數值會是 13)

但當兩個字串相加時:
let a = "5";
let b = "8";
let c = a + b; (c的值會是 "58")

若果一個數字加上字串呢?
let a = 5;
let b = "8";
let c = a + b; (c的值會是 "58",兩組都會轉變成字串看待)

若果一個字串加上數字呢?
let a = "5";
let b = 8;
let c = a + b; (c的值會是 "58",兩組都會轉變成字串看待)



If you want the service of Web Design, do contact us immediately!



Contact



Send a Message

Sed diam nonummy nibh euismod tincidunt ut laoreet dolore magnais.