Discussion: Hexorcism

Execute the code to understand the output and gain insights into how JavaScript handles arithmetic operations and type conversions.

Verifying the output

Now, it’s time to execute the code and observe the output.

Press + to interact
const hex = "0x1E";
console.log(hex - 0);

Understanding the output

This JavaScript code outputs 30 because of the way JavaScript handles arithmetic operations and type conversions. The 0x part is a prefix used in JavaScript to indicate that a number is in hexadecimal format. Hexadecimal numbers use a base-16 system instead of the usual base-10 (decimal) system ...