Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

72
Views
Javascript Ternary question about Codecademy's high-order functions exercises

I am going through Codecademy's Into to JS course and I stumbled on a problem. https://www.codecademy.com/courses/introduction-to-javascript/lessons/higher-order-functions/exercises/review for reference.

I can't understand why the function containing the ternary returns "undefined", while the function containing the "if-else" statement works.

const addTwo = num => {
  return num + 2;
}

const checkConsistentOutput = (func, val) => {
  const checkA = val + 2
  const checkB = func(val)
  if (checkA === checkB) {
    return func(val)
  } else {
    return "inconsistent results"
  }
}

console.log(checkConsistentOutput(addTwo, 5));

VS

const addTwo = num => {
  return num + 2;
}

const checkConsistentOutput = (func, val) => {
  const checkA = val + 2
  const checkB = func(val)
  checkA === checkB ? func(val) : "inconsistent results"
}

console.log(checkConsistentOutput(addTwo, 5));

What am I missing and how should I write the ternary statement in order to make it work?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!