Loging a function to the console?


#1


Guys how would you print or log a function to the console?
In the following code, I want to log the context of the function myObj.rubiks to the console.
I put it in a function so that I could use it again easily.


Replace this line with your code. 
var myObj = new Object();

myObj.name = " Srinjoy ";
myObj.age = " 13 ";
myObj.rubiks = function() {
    console.log('His name is' + this.name + 'and he is' + this.age + 'years old.' )
    return;
};

console.log(myObj.rubiks);


#2

Since myObj.rubiks is a function with a console.log statement, try calling the function itself using correct syntax.

Example:

function();


#3

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