Saturday, 22 December 2018

How to represent Hexadecimal numbers in JavaScript?

Hexadecimal numbers are represented by a leading 0X or 0x followed by characters 0123456789ABCDEF.

HelloWorld.js
var x = 0xFF;
var y = 0XFF;

console.log("x : " + x);
console.log("y : " + y);

Output
x : 255
y : 255

If the digits after 0x contains characters other than 0123456789ABCDEF, SyntaxError is thrown.



Previous                                                 Next                                                 Home

No comments:

Post a Comment