เครื่องหมายบวก (+) ก่อนตัวแปรกำหนดว่าตัวแปรที่คุณจะใช้เป็นตัวแปรตัวเลข
ในโค้ดด้านล่างมีคำอธิบายสั้น ๆ เกี่ยวกับเครื่องหมายบวก ต่อไปนี้เป็นรหัส -
ตัวอย่าง
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