What Does the "0x" Prefix Mean in JavaScript?

In JavaScript (and almost all other programming languages), 0x is used to indicate that all subsequent characters should be interpreted as hexadecimal (base 16 number system). For example:

console.log(0x20); // 32
console.log(0x6b6c); // 27500

You can also convert a number into its corresponding hexadecimal value in the following way:

console.log(Number(32).toString(16)); // '20'
console.log(Number(27500).toString(16)); // '6b6c'

This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.