About 341,000 results
Open links in new tab
  1. javascript - How to use ternary operator for a return in JS?

    Aug 11, 2018 · The ternary (conditional) operator expects the "expr1" part (where return answers is) to be an expression - that is, something that can be evaluated to a value, which can be …

  2. javascript - Why can't we have return in the ternary operator?

    The ternary operator evaluates to an expression and expressions can't contain a return statement (how would that behave if you were to assign the expression to a variable?). However, you …

  3. Conditional (ternary) operator - JavaScript | MDN - MDN Web Docs

    Mar 13, 2025 · The conditional (ternary) operator is the only JavaScript operator that takes three operands: a condition followed by a question mark (?), then an expression to execute if the …

  4. Does a ternary operator has a return value in javascript?

    May 27, 2022 · Return statement ends function execution and provides requested value. So if you want to return from the function, you basically use ternary operator on the right side of return: …

  5. How to Use the Ternary Operator in JavaScript – Explained with …

    Feb 27, 2024 · A ternary operator is a conditional operator in JavaScript that evaluates a conditional expression and returns either a truthy or falsy value. To understand how this …

  6. JavaScript Ternary Operator - GeeksforGeeks

    Apr 15, 2025 · Returns a Value: It directly gives you a result, which can be used right away (like in assignments). Can Be Nested: You can use it inside another ternary operator to check multiple …

  7. JavaScript Ternary Operator – Syntax and Example Use Case

    Jan 6, 2023 · What is the Ternary Operator? The ternary operator is a conditional operator which evaluates either of two expressions – a true expression and a false expression – based on a …

  8. How to Use the Ternary Operator in JavaScript – JS Conditional …

    Feb 27, 2023 · The ternary operator always returns a value that you assign to a variable: const returnValue = condition ? ifTrueExperssion : ifFalseExpression; Next, let's look at an example …

  9. JavaScript Ternary Operator: Syntax, Usage, and Examples

    The JavaScript ternary operator offers a quick and compact way to write conditional expressions. Instead of using a full if...else statement, you can evaluate a condition and return a value in a …

  10. JavaScript: Ternary Operator

    May 5, 2025 · The ternary operator is a great tool for simplifying functions that return values based on conditions. Instead of using multiple if-else statements, the ternary operator allows …

  11. Some results have been removed
Refresh