I want to use the attribute data-srcwhen screen.width > 767and data-src-smallwhen screen.width < 768. I have two methods:
Method 1:
var src = "data-src";
if($(window).width() < 768) {
src = "data-src-small";
}
Method 2:
if($(window).width() > 768) {
var src = "data-src";
}
else {
var src = "data-src-small";
}
I have encountered this situation twice. Therefore, I think it is important to know which method works best, since this situation may come later.
Edit: I don't want this question to be javascript specific. In general, I mean, is this a quick, variable reassignment or an additional condition for evaluating in else? The same situation can be in C as follows:
string salary;
...
...
salary = "LOW";
if(person == "RICH") {
salary = "HIGH";
}
Method 2:
string salary;
...
...
if(person == "RICH") {
salary = "HIGH";
}
else {
salary = "LOW";
}
, Chrome V8 javascript gcc-4.9.2 C.