-4

I tried this in my code and also in the Chrome console and it's not doing what I want. Do you know why it's not working?

let r = 'd';
r == 'e' ? console.log('itisE') : 
r == 'd' ? console.log('itisD') : console.log('nothing');

Chrome's console prints "undefined", it doesn't execute the function calls. Neither does my code (in my code, it's for UI changes of various buttons).

user1944491
  • 559
  • 1
  • 8
  • 24

1 Answers1

-1

I assume that you are talking about in the google chrome browser -> developer tools and then the console inside them.

the console works in a way that it has to return/print any value to you, in this case, the let r = 'd' its not printing anything, for that reason shows undefined; becasue the console always does a Console.log() on the background.

and when you assign a value you are not really printing/returning anything, thats why you see undefined;

TiGreX
  • 1,602
  • 3
  • 26
  • 41
  • It returns 'd' for the variable creation. It returns undefined for the ternary expressions. So your whole answer is invalid. – user1944491 Oct 13 '21 at 21:55
  • 1
    @user1944491 No, the answer is mostly correct. Only a little detail is wrong. It's not `let r = 'd';` but one of the `console.log` calls. `console.log` returns `undefined`. That's the `undefined` you see in your browser's console. – jabaa Oct 13 '21 at 21:57
  • Can you recommend a function invocation to use that can be differentiated? Why wouldn't the log be updated with the message? Because it's only acknowledging the existence of the function and not executing it, similar to if you enter "function x(){}" – user1944491 Oct 13 '21 at 22:04
  • @user1944491 `function x(){}` is a function definition. It's not a function call. The function is not called with `function x(){}` – jabaa Oct 13 '21 at 22:05