-2

Could I get insight on why this returns undefined?

  let obj = {
    something:"ok"
}
  var i = 1;
  var b = 1;
  const testing = () => {
     i === b ? obj.something : "nothing"
}
   console.log(testing());
  • 1
    It throws a `ReferenceError`, `cool` is not defined – ASDFGerte Nov 13 '19 at 01:20
  • Because it is not defined – JK. Nov 13 '19 at 01:21
  • Please read the documentation on [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions). `testing` doesn’t return anything. – Sebastian Simon Nov 13 '19 at 01:24
  • Possible duplicate of [ES6 arrow function returns undefined instead of desired value](https://stackoverflow.com/questions/44852417/es6-arrow-function-returns-undefined-instead-of-desired-value) – Sebastian Simon Nov 13 '19 at 01:25

1 Answers1

0

You have no return statement in testing. Change to this and should work:

let obj = {
    something:"ok"
}

var i = 1;

var b = 1;


const testing = () => {
     return (i === b ? obj.something : "nothing");
}

console.log(testing());
jacob13smith
  • 919
  • 5
  • 12