What is the primary purpose of the ternary operator (condition ? expr1 : expr2) in JavaScript?
The primary purpose of the ternary operator (condition ? expr1 : expr2) in JavaScript is to provide a concise way to write an if-else statement. It evaluates the condition, returns expr1 if the condition is true, and expr2 if the condition is false. For example, let status = age >= 18 ? 'adult' : 'minor'; is equivalent to if(age >= 18) { status = 'adult'; } else { status = 'minor'; }, but is more concise. The ternary operator is particularly useful for simple conditional assignments or for inline conditional expressions in JSX or template literals.