I am curious, is there any difference in both comparison in if condition
No. JavaScript just lets you use either kind of quotes around a string literal in your code. The only difference is that inside a string literal quoted with "
, you have to escape the "
character, but not the '
character; inside a string literal quoted with '
, you have to escape '
but not "
. There is no difference at all in the resulting string, it's purely about how you write the literal in the code.
Examples:
var s1 = "I'm a string"; // Doesn't need \ before '
var s2 = 'I\'m a string'; // Does need \ before '
console.log(s1 === s2); // true, they're the same string
var s3 = 'He said "Hello," smiling'; // Doesn't need \ before "
var s4 = "He said \"Hello,\" smiling"; // Does need \ before "
console.log(s3 === s4); // true, they're the same string
So regarding the if
:
if(varArray[i] == '' || varArray[i] == "")
The second half of that is completely unnecessary.
is it specific to browser.
No.