How do I alert as FF and not 255 with this:
var myHex1 = 0xff;
alert(myHex1);//alerts 255
var myVar = 255;
var myHex2 = myVar.toString(16);
alert(myHex2);//also alerts 255 and not FF
How do I alert as FF and not 255 with this:
var myHex1 = 0xff;
alert(myHex1);//alerts 255
var myVar = 255;
var myHex2 = myVar.toString(16);
alert(myHex2);//also alerts 255 and not FF
Your second example works for me exactly how it is. Are you sure you're alerting the right variable in your test?
And standard compliant approach is:
var x = 0xFF; window.alert(x.toString(16)); //ff
Regards.