Methods complex like a puzzle - pictured as word Methods on a puzzle pieces to show that Methods can be difficult and needs cooperating pieces that fit together, 3d illustration


In JavaScript, methods are function that exist on an object. Here is an example…

class Animal {
    constructor(name){ = name;
        return ${} says “ugh!”;
    } }
let gorilla = new Animal(‘Bongo’);

This code would output Bongo says “ugh!”. Notice that we did not use the function keyword. We did need the return though.

Note: You might notice that we used backticks in this example. You also might notice something odd. We used a dollar sign ($) and curly braces ({}) in our line of log code. This syntax allows for interpolation. We can put a variable inside the curly braces and the code will display the value of the variable.

Happy Coding!

Clay Hess

Share this post

Excuse Our Mess! We are currently remodeling!

We are currently in the process of redesigning our site. We appreciate your patience as some areas of our site show chipping and paint peeling. We hope to have it sparkling soon!

Skip to content