difference in single quote and double quote while doing comparison in javascript -
var str = ' 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 piece of code blogs. curious, there difference in both comparison in if condition . specific browser. please me know reason of using this. or both same.
i curious, there difference in both comparison in if condition
no. javascript lets use either kind of quotes around string literal in code. only difference inside string literal quoted "
, have escape "
character, not '
character; inside string literal quoted '
, have escape '
not "
. there no difference @ all in resulting string, it's purely how write literal in code.
examples:
var s1 = "i'm string"; // doesn't need \ before ' var s2 = 'i\'m string'; // need \ before ' console.log(s1 === s2); // true, they're same string var s3 = 'he said "hello," smiling'; // doesn't need \ before " var s4 = "he said \"hello,\" smiling"; // need \ before " console.log(s3 === s4); // true, they're same string
so regarding if
:
if(vararray[i] == '' || vararray[i] == "")
the second half of unnecessary.
is specific browser.
no.
Comments
Post a Comment