شرح صفوف ومحتوى الفقرة
عامل Unary plus (+) يسبق القيمة أو المتغير ليحاول تحويلها ال Number رقم صحيح اذا لم يكن كذلك أي انه يقوم بتحويل الي ارقام.
يمكنه تحويل انواع البيانات Data Types التالية الي ارقام سواء كانت integers ارقام صحيحة أو floats ارقام كسرية أو hexadecimal عشرية أو scientific (exponent) notation القيم الأوسية أو Infinity:
- boolean values القيم المنطقية (true and false)
- null القيم الغير معروفة
- string جميع النصوص
Plus Unary Operators string to number
تحويل النصوص String الي رقم Number عن طريق Plus Unary Operators في لغة جافا سكريبت
let x = "3";
let y = +x;
document.write("<b>" + typeof(x) +"<b><br>");
document.write("<b>" + y +"<b><br>");
document.write("<b>" + typeof(y) +"<b><br>");
Plus Unary Operators minus string
تحويل النصوص String الي رقم Number سالب عن طريق Plus Unary Operators في لغة جافا سكريبت
let x = "-3";
let y = +x;
document.write("<b>" + typeof(x) +"<b><br>");
document.write("<b>" + y +"<b><br>");
document.write("<b>" + typeof(y) +"<b><br>");
Plus Unary Operators minus string
تحويل النصوص String الي رقم Number كسري floats عن طريق Plus Unary Operators في لغة جافا سكريبت
let x = "3.5";
let y = +x;
document.write("<b>" + typeof(x) +"<b><br>");
document.write("<b>" + y +"<b><br>");
document.write("<b>" + typeof(y) +"<b><br>");
Plus Unary Operators plus float number
تحويل النصوص String الي رقم Number كسري floats عن طريق Plus Unary Operators في لغة جافا سكريبت
let x ="123e-5"; /* 123e-5 = 0.00123 */
let y = +x;
document.write("<b>" + typeof(x) +"<b><br>");
document.write("<b>" + y +"<b><br>");
document.write("<b>" + typeof(y) +"<b><br>");
Plus Unary Operators plus Hexadecimal
تحويل Hexadecimal الي رقم Number عن طريق Plus Unary Operators في لغة جافا سكريبت.
let x = "0xFF"; /* 0xFF = 255 */
let y = +x;
document.write("<b>" + typeof(x) +"<b><br>");
document.write("<b>" + y +"<b><br>");
document.write("<b>" + typeof(y) +"<b><br>");
Plus Unary Operators true
تحويل العوامل المنطقية الي رقم Number عن طريق Plus Unary Operators في لغة جافا سكريبت.
let x = true; /* true = 1 */
let y = +x;
document.write("<b>" + typeof(x) +"<b><br>");
document.write("<b>" + y +"<b><br>");
document.write("<b>" + typeof(y) +"<b><br>");
Plus Unary Operators false
تحويل العوامل المنطقية الي رقم Number عن طريق Plus Unary Operators في لغة جافا سكريبت.
let x = false; /* false= 0 */
let y = +x;
document.write("<b>" + typeof(x) +"<b><br>");
document.write("<b>" + y +"<b><br>");
document.write("<b>" + typeof(y) +"<b><br>");
Plus Unary Operators null
تحويل العوامل الغير معروفة الي رقم Number عن طريق Plus Unary Operators في لغة جافا سكريبت.
let x = null; /* null= 0 */
let y = +x;
document.write("<b>" + typeof(x) +"<b><br>");
document.write("<b>" + y +"<b><br>");
document.write("<b>" + typeof(y) +"<b><br>");
Plus Unary Operators Infinity
تحويل العوامل الغير معروفة الي رقم Number عن طريق Plus Unary Operators في لغة جافا سكريبت.
let x = "Infinity"; /* Infinity= Infinity*/
let y = +x;
document.write("<b>" + typeof(x) +"<b><br>");
document.write("<b>" + y +"<b><br>");
document.write("<b>" + typeof(y) +"<b><br>");
Plus Unary Operators NaN
تحويل النصوص الي Number الي NaN عن طريق Plus Unary Operators في لغة جافا سكريبت.
let x = "not a number"; /* not a number = NaN*/
let y = +x;
document.write("<b>" + typeof(x) +"<b><br>");
document.write("<b>" + y +"<b><br>");
document.write("<b>" + typeof(y) +"<b><br>");