From the course: Learning CoffeeScript

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Adding basic functions

Adding basic functions - CoffeeScript Tutorial

From the course: Learning CoffeeScript

Start my 1-month free trial

Adding basic functions

It's almost impossible to talk about CoffeeScript without doing functions, and you've already seen me use a few examples. Let's go ahead and spend some time focusing on them in this movie. Now, you probably already know that the function keyword is gone in CoffeeScript, along with parentheses. You don't need to use either of those. You can create a function by doing something like this, creating the name and then using the equals sign plus the dash and the greater than sign. And then, you can execute any statement you want. And that creates the function and also creates the variable for the function automatically. So it's name-spacing the function for you. This function's not executing, because we haven't invoked it. You can invoke the function just by calling it by name. When you do that, though, if it doesn't have any parameters, you are going to need the parentheses. So if you say myFunction, notice that it will say Hello here now in the console. If you try to call it without…

Contents