有人可以为我解释一下 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