Why no semi-colon at end of curly bracket in this exercise


I’m working on the “Accessing Objects Properties with Variable” (https://www.freecodecamp.org/challenges/accessing-objects-properties-with-variables) exercise right now and noticed that there is no semi-colon at the end of the Object’s curly bracket. So far, all of the accessing objects lessons have ended the object with a curly bracket and semi-colon. Why the change?



I see a semi-colon when I visit. Click the “Reset your code” button and then click the “Clear my code” button to reset everything back to the default, you should see this:

// Setup
var testObj = {
  12: "Namath",
  16: "Montana",
  19: "Unitas"

// Only change code below this line;

var playerNumber;       // Change this Line
var player = testObj;   // Change this Line


I just noticed that, but I was referring to their examples on the left.


I didn’t notice that. Looks like it’s a typo covered here:

It has been fixed - perhaps that means it will be addressed in the beta - or eventually merged into the live challenge that you linked to in your original comment.


Semicolons are weird in JS. Sometimes they’re required, sometimes they’re verboten, and sometimes they’re kinda optional.

This runs fine:

const PI = 3.14159
var radius = 10

var circle = { radius: radius, circumference: radius*2*PI }

console.log("radius = " + circle.radius)
console.log("circumference = " + circle.circumference)

And so does this:

const PI = 3.14159;
var radius = 10;

var circle = { radius: radius, circumference: radius*2*PI };
; ; 
console.log("radius = " + circle.radius); ; ; ; ; 
console.log("circumference = " + circle.circumference);

There are a few boobytraps and definite no-nos, but there is a lot of leeway. I think tend not to put them after curly braces (since that’s a code block) and put them in other places (but there is probably an exception or two that is not coming to mind.) If you put in an extra semicolon, I think it just gets interpreted as an empty line.

If you look around online you’ll find guides like this.


Semicolon automatic insertion possibly. JavaScript engine reads your code character by character and if there isn’t a semicolon where it expects one it will add it as it determines what’s valid syntax.