Is this the correct way? I want the statement to run if the value of somevar equals the string?
if (somevar = '836e3ef9-53d4-414b-a401-6eef16ac01d6'){
$("#code").text(data.DATA[0].ID);
}
Is this the correct way? I want the statement to run if the value of somevar equals the string?
if (somevar = '836e3ef9-53d4-414b-a401-6eef16ac01d6'){
$("#code").text(data.DATA[0].ID);
}
No. = sets somevar to have that value. use === to compare value and type which returns a boolean that you need.
Never use or suggest == instead of ===. its a recipe for disaster. e.g 0 == "" is true but "" == '0' is false and many more.
More information also in this great answer
NO, when you are using only one "=" you are assigning the variable.
You must use "==" : You must use "===" :
if (somevar === '836e3ef9-53d4-414b-a401-6eef16ac01d6'){
$("#code").text(data.DATA[0].ID);
}
You could use fonction like .toLowerCase()
to avoid case problem if you want
First of all you should use double "==" instead of "=" to compare two values. Using "=" You assigning value to variable in this case "somevar"