How to reassigned object inside property(function)

Problem changing

let school={
  shName:'Rp public',
console.log("Today's Day is " today(){
  return 'Sunday';
console.log("Today's Day is "

Hi, and welcome to the forums!

One thing to recall with regards to object methods is the difference between fetching a method and calling a method. When you do

// logs "Monday"

You are calling the method, as you have added the brackets at the end. Therefore this runs the method and returns the result. However if you want to fetch the actual content of a method, you have to call it like you would any other property.
// logs "[Function: today]"

In this one, you are fetching the actual method itself without calling and running it. This is what you need to overwrite if you want to replace it with a new method content. Therefore it should be = function today() {//your code here}
1 Like