0x0001
is an integral constant in base 16, i.e., hexadecimal. It is still 1
in base 10. So yes, your example is equivalent, but do you know how to mentally parse 0xBC
? If not then you need to study up on arbitrary base arithmetic or at least get comfortable with hex as any programmer should know this stuff.
Sometimes it is easier to view numbers in hex form as they represent bit patterns. In hex, two digits correspond to a byte, so you know at a glance that 0xFF
is 255
base 10 and 11111111
base 2. Work on some lower level projects for a while and it will become second nature.
In your C++ example the integral constants are textually replaced by the preprocessor (i.e., all occurrences of FIRST_THING
are replaced by 0x0001
before the code is compiled), you don't have such a tool in javascript, so just assign the values to variables directly.
You cannot create 'constants' in javascript, so it's up to you to make sure that you don't change them. However, you can simply write
firstThing = 0x0001;
And it will work just as the C++ example does, i.e., firstThing
takes on the value of 1
.