Javascript Functions and Objects - Destructured Assignment Sections

Hey Guys – for some reason, when I console.log a function that calls on part of an object, I often get the right output but it also prints undefined. I have left an example of the code below. Anyone know what is the issuse?

const robot = {

model: ‘1E78V2’,

energyLevel: 100,

functionality: {

beep() {

  console.log('Beep Boop');


fireLaser() {

  console.log('Pew Pew');




const { functionality } = robot;

console.log(functionality.beep()); // returns “Beep Boop undefined”

You only need to do:


This is because your methods in the object do the console.log already. Those methods don’t return anything so they will default to returning undefined. The main console.log that you were doing was on this undefined value (returned from the .beep function). Therefore, you were previously doing console.log twice.