in JavaScript by
Which of the following is the correct output for the following JavaScript code:

function display1(option)  

{  

    return(option ?  "true" :  "false");  

}  

    bool ans=true;  

console.log(display1(ans));  

a) False

b) True

c) Runtime error

d) Compilation error

1 Answer

0 votes
by

Answer: B

Reason: In the following JavaScript code, the "?" is being used which is also known as ternary operator". Here it is used to choose one option as a choice among the given two options. However, it is often used to write shorter and simple code because it can be used in the place of "if else" statements.

Related questions

0 votes
asked Mar 21, 2021 in JavaScript by rajeshsharma
0 votes
asked Mar 23, 2021 in JavaScript by sharadyadav1986
0 votes
asked Mar 21, 2021 in JavaScript by rajeshsharma
...