I have recently started learning Javascript and want to understand how functions declared inside an object work. i have defined a function inside an object and just logged a message "Function functionName is called" inside it. When i call the function the console logs the message but along with it "undefined" also gets printed on the subsequent line. i understand that my function doesn't return anything and hence by default javascript returns undefined. But i need to know is there a way to write functions that return nothing similar to void functions() in java?
Here's my code -
const circle = {
radius : 5,
location : {
x: 10,
y : 1
},
isVisible : true,
draw : function(functionName){
console.log('Function '+functionName+' is called. ');
}
};
console.log(circle.isVisible); // true
console.log(circle.radius); // 5
console.log(circle.location); // { x: 1, y: 1 }
console.log(circle.location.x); // 10
console.log(circle.draw('draw'));