ES2019 — 2020 JAVASCRIPT представил числовой разделитель. В блоге есть примеры использования числового разделителя.
For e.g We are building a financial application and it has large calculations of 250 million. Please note the This can lead to a lot of mistakes for the programers as a zero more or zero less makes a huge difference. In real- life we would write the its with commas 250,000,000 In Javascript we cannot separate the numbers with commas as commas have different meaning in Javascript. const lotaMoney = 250000000; However now in ES2019 and ES2020 we can separate the numbers using underscore _ . It works for both floating numbers and whole. const lotaMoney = 250_000_000.012_304; console.log(lotAmoney) -> 250000000.012304 const lotaMoney = 250_000_000; console.log(lotAmoney) -> 250000000. The separator works in different currency as the _ might have to be in different position for different currency. eg const Rupees = 1_00_0000. console.log(rupees) 1000000 However you will not see the separator in your log. You will get syntax errors if you put in the underscore before or after. const lotaMoney = _100_000_ console.log(lotaMoney) //Error Lets try this with Binary = We will use octet separator - Separate by 8; nimble separator = Separate by 4; const b = 0b000000_11111111; console.log (b) //255 //255 Works fine. Let's try with giant Number = Usually in Javascript if you exceed more than 16 digits it creates problem. const giant = 1234567812345678023; console.log(giant) The result are not the same. //12345678123456788000 If you use 'n'; const giant = 1234567812345678023n; console.log(giant) // [object BigInt] {}; It will return you an object to print this you will have to inspect it and when you inspect it in your console you will end up with same results. On console log it will give you in the form of BigInt. // 1234567812345678023n You can also add numeric separator for readability and you will ge the same results. const giant = 123_4567_81234_567_8023n; console.log(giant) Browser Compatibility - They are Firefox Chrome Edge Transpiler - Babel Typescript.