I'm very new to JavaScript and I'm trying to learn some basics practicing with it.
I've got stuck with this:
var name = prompt('enter your name', '');
if( name == null ) {
alert('Cancelled');
} else if ( name == 'admin' ) {
alert('hi admin');
} else {
alert('I don\'t know you');
}
If I press esc (or cancel button) I should get 'Cancelled' message, but it's 'I don\'t know you' by some reason.
But the fun part is if I'll rename variable to something else, for ex.:
var usr = prompt('enter your name', '');
if( usr == null ) {
alert('Cancelled');
} else if ( usr == 'admin' ) {
alert('hi admin');
} else {
alert('I don\'t know you');
}
...It will work just fine.
What's wrong? I've tried it in different browsers, I've googled forbidden variable names, but I have no answer.
PS: I know that esc or cancel will return empty string in safari, but it happens in all browsers