Correct JavaScript Syntax

Hi there,
I keep on noticing on the supporting videos that we get for the JavaScript exercises (i.e: Menu Maker vs Lodash Library) that the syntax of the coders changes, is that normal?
Like:

inRange(number, start, end) {
if(end === undefined) {
end = start
start = 0
}if(start > end) {
var temp = end
end = start
start = temp
} var isInRange = start <= number && number < end
return isInRange
}

Whereas the syntax on the Menu Maker is totally different:

addDishToCourse(courseName, dishName, dishPrice) {
const dish = {
name: dishName,
price: dishPrice
};
return this._courses[courseName].push(dish);
},
getRandomDishFromCourse(courseName) {
const dishes = this._courses[courseName];
const randomIndex = Math.floor(Math.random() * dishes.length);
return dishes[randomIndex];
},
generateRandomMeal() {
const appetizer = this.getRandomDishFromCourse(‘appetizers’);
const main = this.getRandomDishFromCourse(‘mains’);
const dessert = this.getRandomDishFromCourse(‘desserts’);
const totalPrice = appetizer.price + main.price + dessert.price;
return Your meal is ${appetizer.name}, ${main.name}, ${dessert.name}. The price is ${totalPrice}.;

I didn’t have the sense of an unified syntax criteria across coders/teachers and I’d love to have a clear understanding :pray:t4:

There’s not one unified javascript standard that I know of. Different employers will have conventions that vary and one should be adaptable for a variety of conventions.

That said, the MDN docs do outline a “best practice” style guide. Also, javascript changes at a quicker pace than other languages (like Java, Python) so the style will also reflect those changes. It’s good not too get too used to one way in javascript.

If you learn a language like python or java you will get a better sense of a language that works with unified syntax (esp. python). My suggestion is to keep the mdn page bookmarked until you feel at home with it and try to make your syntax follow it… but don’t be too fussed if you see other people diverge.

2 Likes