Answer the question
In order to leave comments, you need to log in
Why does this code work and how to correctly return values in return according to the conditions?
Please explain this code
var x = undefined;
var y = true;
function test(x, y) {
var z = '';
var count = 0;
return 1 == x && (z += "взяли x<br>", count += 1),
1 == y && (z += "взяли y<br>", count += 1),
z += 'Кол-во переменных: ' + count,
z
}
document.write(test(x,y)); // выведет 'взяли y Кол-во переменных: 1'
Answer the question
In order to leave comments, you need to log in
Why does it work, what is this construct in return?Because it is correct and syntactically correct code without errors. Somewhat confusing, but that doesn't stop it from working properly.
&&
- this is a logical AND. And there are also commasAnd why doesn't the design look like a classic...Actually a very strange question. This thing looks different because it was written differently.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question