Webolution Designs

Methods

Share This Post

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

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

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

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

Code

Curriculum Innovation or Confusion

It is an early Monday morning just prior to the beginning of the semester.  A faculty member walks into the institution where he teaches.  He

Code

Creating a Promise

Promises are used for asynchronous code. It is a temporary holder for a value that gets returned by an asynchronous call. For example, a call

Do You Want To Boost Your Business?

drop us a line and keep in touch

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!

small_c_popup.png

Learn how we helped 100 top brands gain success.

Let's have a chat