-2
 var str = ' some value, 1, 2 , test3'; 
   str +="test string, 12, test12";   
   var varArray = new Array();
   varArray = str .split(",");
   if(varArray[i] == '' || varArray[i] == "")
   {
    //some logic
    }

I have referred this piece of code from some blogs. I am curious, is there any difference in both comparison in if condition . is it specific to browser. Please help me to know the reason of using this. or both are same.

Ankuli
  • 131
  • 7

1 Answers1

0

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.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875