有人可以為我解釋一下 JavaScript 中變數之前的加號是什麼嗎?
變數之前的加號 (+) 定義了你要使用的變數為數字變數。
在以下程式碼中,對加號進行了簡要說明。程式碼如下 −
示例
var firstValue="1000";
console.log("The data type of firstValue ="+typeof firstValues);
var secondValue=1000;
console.log("The data type of secondValue ="+typeof secondValue);
console.log("The data type of firstValue when + sign is used ="+typeof
+firstValue);
var output=+firstValue + secondValue;
console.log("Addition is="+output);要執行上述程式,需要使用以下命令 −
node fileName.js.
輸出
此處,我的檔名是 demo149.js。這將產生以下輸出 −
PS C:\Users\Amit\JavaScript-code> node demo149.js The data type of firstValue =string The data type of secondValue =number The data type of firstValue when + sign is used =number Addition is=2000
廣告
資料結構
網路
關係型資料庫
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言
C++
C#
MongoDB
MySQL
Javascript
PHP