Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Introducing ES2015 The Cooler Parts of ES2015 Default Parameters

Why am I getting this error in the console?

$ node default-parameters.js
C:\Users\Rusie\Documents\susan_treehouse\Introducing_ES2015\Default_Parameters\s
tart\default-parameters.js:3
function greet(name = 'Guil', timeOfDay = 'Day') {
                    ^

SyntaxError: Unexpected token =
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)
    at node.js:968:3

Here is my code:

'use strict';

function greet(name  =  'Guil',  timeOfDay  =  'Day') {
  console.log(`Good ${timeOfDay}, ${name}!`);
}

greet(undefined, 'Afternoon');

I have played around with the spacing on that line, but I still get the same error. What am I doing wrong?

2 Answers

Jonathan Dewitt
Jonathan Dewitt
8,101 Points

This code also works for me when copy-pasted into my own file with zero edits. I am using node v6.9.2.

Rogier, Updating Node is what was needed. Everything is now working as it should. Thanks for your help.