You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ES5 provided numeric literals in octal (prefix 0), decimal (no prefix), and hexadecimal ( 0x) representation. ES6 added support for binary literals and improvements on octal literals.
899
+
900
+
**1. Binary literals:**
901
+
902
+
Prior to ES5, JavaScript didn’t provide any literal form of binary numbers. So you need to use a binary string with the help of `parseInt()`
903
+
904
+
```js
905
+
constnum=parseInt('111',2);
906
+
console.log(num); // 7
907
+
```
908
+
909
+
Whereas ES6 added support for binary literals using the **0b** prefix followed by a sequence of binary numbers (i.e, 0 and 1).
910
+
911
+
```js
912
+
constnum=0b111;
913
+
console.log(num); // 7
914
+
```
915
+
916
+
**2. Octal literals:**
917
+
918
+
In ES5, to represent an octal literal, you use the zero prefix (0) followed by a sequence of octal digits (from 0 to 7).
919
+
920
+
```js
921
+
constnum=055;
922
+
console.log(num); // 45
923
+
924
+
let invalidNum =058;
925
+
console.log(invalidNum); // treated as decimal 58
926
+
```
927
+
928
+
Whereas ES6 represents the octal literal by using the prefix **0o** followed by a sequence of octal digits from 0 through 7.
929
+
930
+
```js
931
+
constnum=055;
932
+
console.log(num); // 45
933
+
934
+
constinvalidNum=058;
935
+
console.log(invalidNum); // treated as decimal 58
936
+
```
937
+
938
+
Remember If you use an invalid number in the octal literal, JavaScript will throw a SyntaxError as below,
939
+
940
+
```js
941
+
constinvalidNum=058;
942
+
console.log(invalidNum); // SyntaxError
943
+
```
944
+
945
+
884
946
### Proper Tail Calls
885
947
**Proper tail call(PTC)** is a technique where the program or code will not create additional stack frames for a recursion when the function call is a tail call.
While creating symbols, you also can add a description to it for debugging purposes. But there was no method to access the description directly before ES2019. Considering this, ES2019 introduced a read-only description property to retrieve a string containing the description of the Symbol.
1344
1407
1345
1408
This gives the possibility to access symbol description for different variations of Symbol objects
0 commit comments