Javascript Conditionals' behaviour