Skip to main content
Table of contents

Back to challenges

Challenge 2 - ES5 to ES6

This code is written in ES5. Using your newfound JavaScript knowledge, try to refactor these small functions in ES6 and output the same results.

Define a function greetings that returns Hello my name is Sarah!

function greetings(name) {
    return 'Hello my name is' + name + '!'
}
greetings('Sarah')

BONUS

Which value does w, x, y, z have after execution of the following code?

var w = 'Ella'
var x = 'John';
var y = 'Marie';
var z = y;
y = x;
x = z;
console.log('Here is ' + z + ', ' + y + ' and ' + w )

In these exercises, we add a special bonus to go a bit further than the lesson… Have a look about a new ES6 concept: the template literals and variables substitutions.

Solution

Next challenge

This page was last reviewed on 3 February 2022. It needs to be reviewed again on 3 February 2023 .
This page was set to be reviewed before 3 February 2023. This might mean the content is out of date.