CodeOrc.com - Learn by example
X
Make an RPG
Vue Implementations

Examples of Functions and Parameters

Let's talk about what functions and parameters look like in the new Javascript. In ES6, the syntax for functions have changed. Here is the old syntax.

var fun0 = function() {};

or

function fun1() {}

Here is the new syntax:

var fun_new = () => {}

The first part says "Here is a variable"

var fun_new = ()

The second part says "It's a function and here it is".

=> {}

Default Parameters

You can define defaults for any of your parameters, simply like so:

var render = ( animal = "rabbit", count = 2 ) => { log("Rendered " + count + " animals."); }

You call the function in the same way as before.

render("turtle", 5);
DO IT

Or use the default parameters, like so:

render();
DO IT
Change up the render call parameters and add your own.

Browser Support

If you're worried about browser support, go checkout Compat table ES6. It's pretty thorough. You can see that modern browsers pretty much fully support ES6 since 2017.

If you want some more examples and explanations, I would recommend you check out w3schools ES6 as they have some great explanations.

In the next lesson, we will learn about Examples of how to use Maps and Sets

Get the Latest Tutorial Updates
<< >>
X