Javascript Objects 10/15 - the "this" Keyword I


I am not getting it … it is showing error!! why??


please help!!

thank you!


can you copy paste your code to the forum? The error might be caused by a mistake in the line above, so without the full code its impossible to day


return Hello, my name is ${tyron};

ReferenceError: tyron is not defined
at Object.sayHello (/home/ccuser/workspace/learn-javascript-objects-objects/main.js:8:33)
at Object. (/home/ccuser/workspace/learn-javascript-objects-objects/main.js:23:20)
at Module._compile (module.js:571:32)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)


this was the error i was getting


this part of the error message:

ReferenceError: tyron is not defined

says you have an undefined variable (tyron)

If you want more help, post your full code (like i asked before)


how to post it?? …


you copy paste the code you have to the forum, very similair to what you just did with the error message

let person = {
  name: 'Tyron',
  age: 40,
  weekendAlarm: 'No alarms needed',
  weekAlarm: 'Alarm set to 7AM',
  sayHello: function() {
    return `Hello, my name is ${tyron}`;
  sayGoodbye() {
    return 'Goodbye!';

let friend = {
  name: 'Lebron'

friend.sayHello = person.sayHello;


person.hobbies = ['Basketball', 'Coaching'];
person.hobbies = ['Basketball'];


let day = 'Tuesday';
let alarm;

if (day === 'Saturday' || day === 'Sunday' ) {
  alarm = 'weekendAlarm';
} else {
  alarm = 'weekAlarm';



in our say hello method:

  sayHello: function() {
    return `Hello, my name is ${tyron}`;

we want to reference the name property we defined here:

name: 'Tyron',

in the information section of the issue is addressed how we access properties:

To address this scope issue, we can use the this keyword to access properties inside of the same object.

so if we want to access the name property, we need …?


soo…what should i do??


name is the property we want to access in the sayHello method, to access a properties in a method we need to use this.propertyName, so what should you do?


soo …i have to write


yes, that is what you have to write within the ${} to print the name


yess…now i get it…
thanks bro::smiley::smiley::smiley: