I'm not sure why this happens but I can reproduce it like this:
jsfiddle
status = parseInt($('#input-status').val(), 10);
test = parseInt($('#input-status').val(), 10);
console.log(typeof status); // string
console.log(typeof test); // number
I guess status
is predefined by the browser and can't be parsed.
To make it work use var
to define a new variable in the current scope:
var status = parseInt($('#input-status').val(), 10);
if (status === 0) {
// this also works in chrome
}
EDIT
console.log(window.status === status); // true
It seems like status
is a reference to the window.status
object which changes the status bar in the browser.
And it does make sense that this can't be parsed into a number.
@Xotic750 pointed out:
Yes, on Chrome whenever you set the global variable status/window.status
to any value window.status = {}
then it converts it to a string {value: "[object Object]", writable: true, enumerable: true, configurable: true}
jsfiddle lesson: don't use global variables, use var
to make them locally scoped