in ,

Javascript Notes – Functions

Javascript logo

Basic Syntax

Functions are reusable blocks of code. You can create a function and then call it later. Functions take this simple format:

function functionName() {

//code to run


and then to call them later:



Functions can also take arguments. Lets look at a quick function that adds ten to whatever number is input.

function addTen(num) {




-> 15


Return will always stop the function! It will return the desired result if the conditions are met and then stop the function entirely.

Here are some more sample functions:

Storing Values

coming soon…


setInterval(anotherFunction, interval)

The interval is in milliseconds, so 1 second would be 1000.



Set interval will provide you with a number that you can use to pass into clear interval to stop it.

Anonymous functions


//some code

}, 2000);

If you do not want to pass in another function you can create an anonymous function that just works with this interval and define it there, but you do not need to name it.

Javascript logo

Javascript Notes – String Properties

Javascript logo

Javascript Notes – Arrays