Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

366
Vistas
Javascript: using ternary operator to return default value if a function returns undefined

given this function

function isTastyCheese(cheeseName: string) {
    const TastyCheeses = ['camembert', 'maroilles']
    if (TastyCheeses.includes(cheeseName)) {
        return 'yes so tasty'
    }
    return undefined
}

I'd like to do something like this:

const answerCamembert = isTastyCheese('camembert') ? the_returned_value : 'no taste like sh*t' 
const answerCantal = isTastyCheese('cantal') ? the_returned_value : 'no taste like sh*t'

console.log(answerCamembert)
>>> 'yes so tasty'
console.log(answerCantal)
>>> 'no taste like sh*t'

How do i use ternary operator to do this concisely?

PS: Obsviously the function presented here is very wrong but changing it shouldn't be part of the solution

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda