Friday , September 20 2024

We want to rewrite the following code snippet using the conditional operator: let name; if (test) { name = 10; } else { name = 20; } Which notation is correct?

Questions BankCategory: JavaScript Essentials 1We want to rewrite the following code snippet using the conditional operator: let name; if (test) { name = 10; } else { name = 20; } Which notation is correct?
We want to rewrite the following code snippet using the conditional operator:

let name;
if (test) {
    name = 10;
} else {
    name = 20;
}

Which notation is correct?

  • let name = (test)("Alice")("Bob");
  • let name = if test ? "Alice" : "Bob";
  • let name = test ? "Alice" : "Bob";
  • let name = test : "Alice" ? "Bob";

More Questions: JavaScript Essentials 1 – JSE1: Module 4 Test