ای سی ایم اے اس 2020
شماره نسخه JavaScript
نسخههای قدیمی JS با عدد نامگذاری میشوند: ES5 (2009) و ES6 (2015).
از سال 2016، نسخهها بر اساس سال نامگذاری میشوند: ECMAScript 2016، 2017، 2018، 2019، ...
ویژگیهای جدید ES2020:
- BigInt
- روش matchAll() برای رشتهها
- عملگر ترکیب مقادیر خالی (??)
- عملگر چک کردن چنج (?.)
- عملگر AND منطقی با تخصیص (&&=)
- عملگر OR منطقی با تخصیص (||=)
- عملگر ترکیب مقادیر خالی (??=)
- Promise.allSettled()
- ورود دینامیک
اخطار
این ویژگیها نسبتاً جدید هستند.
مرورگرهای قدیمی ممکن است نیاز به کد جایگزین (Polyfill) داشته باشند.
جاوا اسکریپت بیگ آئن
متغیر BigInt JavaScript برای ذخیره مقادیر بزرگتر از آنچه که میتوان با عدد معمولی JavaScript نشان داد استفاده میشود.
عدد صحیح JavaScript در JavaScript بیش از 15 عدد دقیق نیست.
مثال Integer
let x = 999999999999999; let y = 9999999999999999; // زیاد
مثال BigInt
let x = 9999999999999999; let y = 9999999999999999n;
برای ایجاد BigInt، لطفاً n
به پایان عدد اضافه کنید یا BigInt() را فراخوانی کنید:
example
let x = 1234567890123456789012345n; let y = BigInt(1234567890123456789012345);
نوع JavaScript برای BigInt "bigint" است:
example
let x = BigInt(999999999999999); let type = typeof x;
از 2020 ستمبر، تمامی مرورگرهای مدرن از BigInt پشتیبانی میکنند:
کروم | ایجی | فائر فاکس | سافری | اُپرا |
---|---|---|---|---|
Chrome 67 | Edge 79 | Firefox 68 | سافری 14 | Opera 54 |
May 2018 | January 2020 | July 2019 | 2020 سال ستمبر | June 2018 |
جسٹا اسکریپٹ سٹرنگ میتچ آل()
Before ES2020, there was no string method available to search for all occurrences of a string in a string.
example
const iterator = text.matchAll("Cats");
If the parameter is a regular expression, you must set the global flag (g
) or it will throw a TypeError.
example
const iterator = text.matchAll(/Cats/g);
If you want to perform a case-insensitive search, you must set the case-insensitive flag (i
)
example
const iterator = text.matchAll(/Cats/gi);
Hint:ES2021 introduced the string method replaceAll().
nullish coalescing operator (Nullish Coalescing Operator) (?? operator)
if the first parameter is not a null value (null
or undefined
then ??
operator returns the first parameter.
otherwise return the second.
example
let name = null; let text = "missing"; let result = name ?? text;
since March 2020, all modern browsers support nullish operator:
کروم | ایجی | فائر فاکس | سافری | اُپرا |
---|---|---|---|---|
Chrome 80 | Edge 80 | Firefox 72 | Safari 13.1 | Opera 67 |
February 2020 | February 2020 | January 2020 | 2020 سال مارچ | 2020 سال مارچ |
optional chaining operator (Optional Chaining Operator) (?. operator)
if the object is undefined
or null
thenoptional chaining operatorreturn undefined
(instead of throwing an error).
example
const car = {type:"Fiat", model:"500", color:"white"}; let name = car?.name;
since March 2020, all modern browsers support ?.=
عملگر:
کروم | ایجی | فائر فاکس | سافری | اُپرا |
---|---|---|---|---|
Chrome 80 | Edge 80 | Firefox 74 | Safari 13.1 | Opera 67 |
February 2020 | February 2020 | 2020 سال مارچ | 2020 سال مارچ | 2020 سال مارچ |
منطقی اند (&&= عملگر)
logical AND assignment operatorused between two values.
if the first value is true
,则分配第二个值。
logical AND assignment example
let x = 100; x &&= 5;
2020 سال ستمبر سے، تمام جدید براؤزرز اس کا سپورٹ کرتے ہیں &&=
عملگر:
کروم | ایجی | فائر فاکس | سافری | اُپرا |
---|---|---|---|---|
کروم 85 | ایجی 85 | فائر فاکس 79 | سافری 14 | اُپرا 71 |
2020 سال اگست | 2020 سال اگست | 2020 سال مارچ | 2020 سال ستمبر | 2020 سال ستمبر |
logical OR assignment operator (||= operator)
logical OR assignment operatorused between two values.
if the first value is false
,则分配第二个值。
logical OR assignment example
let x = 10; x ||= 5;
2020 سال ستمبر سے، تمام جدید براؤزرز اس کا سپورٹ کرتے ہیں ||=
عملگر:
کروم | ایجی | فائر فاکس | سافری | اُپرا |
---|---|---|---|---|
کروم 85 | ایجی 85 | فائر فاکس 79 | سافری 14 | اُپرا 71 |
2020 سال اگست | 2020 سال اگست | 2020 سال مارچ | 2020 سال ستمبر | 2020 سال ستمبر |
空值合并赋值运算符(??= 运算符)
空值合并赋值运算符(Nullish Coalescing Assignment Operator)用于两个值之间。
如果第一个值 undefined
或为 null
,则分配第二个值。
خالی جگہ متحد عملگر (??=) مثال
let x = 10; x ??= 5;
2020 سال ستمبر سے، تمام جدید براؤزرز اس کا سپورٹ کرتے ہیں ??=
عملگر:
کروم | ایجی | فائر فاکس | سافری | اُپرا |
---|---|---|---|---|
کروم 85 | ایجی 85 | فائر فاکس 79 | سافری 14 | اُپرا 71 |
2020 سال اگست | 2020 سال اگست | 2020 سال مارچ | 2020 سال ستمبر | 2020 سال ستمبر |