Why do I get "undefined?


I’m learning about “this”…


Can anyone help me why the text string is coming back as “Hello undefined, how are you?”

let person = {
  name: 'Tyron',
  age: 40,
  weekendAlarm: "No alarms needed",
  weekAlarm: "Alarm set to 7am",
  sayHello: () => {
    return `Hello ${this.name}, how are you?`;
  sayGoodbye() {
    return 'Goodbye!';



You need to use es6 for your sayHello method to work correctly with this:

sayHello: function() {
    /* code */

which can be shortened to:

sayHello() {
    /* code */

so far my understanding goes, the behavior of this was changes for es6


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.