DEV Community

Cover image for Learning JavaScript the easy way: JavaScript Grammar
Adetayo Akinsanya
Adetayo Akinsanya

Posted on • Updated on

Learning JavaScript the easy way: JavaScript Grammar

Hi, welcome to my first post on dev.to.

This post will be the first part of the "Learning JavaScript the easy way" series.

The decision to start this series came out of the desire to teach JavaScript concepts in the most understandable way to people who may be struggling with it and also get a deeper understanding of it.

This tutorial is best suited for beginners as it promises a smooth ride and a better understanding of JavaScript concepts from the ground up.

In this part, you will learn about JavaScript grammar, some of which include case-sensitivity, identifiers, comments, statements, and expressions.

Let's dive in πŸš€πŸš€

Javascript Grammar

Every language has its diction, be it a programming language or the native languages we use to communicate with ourselves and Javascript isn't an exception.

Case Sensitivity

JavaScript is a case-sensitive language. This implies that the keywords, variable, function, and many other identifiers must always have consistent capitalization. Therefore, a variable name like user is significantly different from User.

Identifiers

An Identifier can simply be referred to as a name.
In JavaScript, identifiers are used to name variables, functions, parameters, or classes. But these identifiers have certain rules that must be conformed to:

  • A JavaScript identifier must start with a letter, underscore (_), or a dollar sign ($). Subsequent characters can also be digits (0–9), digits, underscores, or dollar signs.

The letters being referred to in this context are not limited to ASCII characters also but may extend to Unicode characters also.

It has become a convention among Javascript developers to use camel case for identifiers, this means that the first letter is lowercase, and each additional word starts with a capital letter. Although it is not mandatory as there are other conventions like kebab case, snake case that can also be used, they just have to abide by the identifier rule

The following are identifier names declared in camelcase

greetingsFromNigeria
containsNumber
isString
routeHere
Enter fullscreen mode Exit fullscreen mode

Comments

They are added with the purpose of making the source code easier for humans to understand, and are generally ignored by compilers and interpreters.

Comments are unexecuted statements in Javascript (more on statements later).

A line of code that comes after double slashes // or block of codes that comes between /* and */ are treated as a comment in JavaScript.
For example

let foo = 6; //  I will be executed
// let bar = 7;  I am not executed

/*
This code won't run.
Because it is a comment
*/
Enter fullscreen mode Exit fullscreen mode

Statements

A statement is a piece of code that can be executed and performs some kind of action.

Although JavaScript doesn't require a statement to end with a semicolon(;), it is recommended to be used when ending a statement.

Personally, I think it makes code readable.
You can use a code block that begins with a left curly brace ({) and ends with the right curly brace (}) to combine multiple statements as follows:

For example,

let today;
if (true){
today = 'Monday';
} else {
today = 'Tuesday';
}
Enter fullscreen mode Exit fullscreen mode

Expressions

An expression is a piece of code that can be evaluated to produce a value.
For example, the following illustrates an expression that involves a and b:

a + b 
Enter fullscreen mode Exit fullscreen mode

Reserved Keywords

There are some keywords that are reserved in JavaScript these keywords cant be used to name variables some of which includes

await,break,case,catch,default,const,continue,debugger,delete,enum,else,export,do,extends,false,finally,for,function,void,static.

There are many other reserved words and keywords in JavaScript that aren't mentioned here, but the good thing is you don't have to memorize them all. However, if you wish to check out other reserved words you can find them here.

In the next part, we will be discussing Variable, its declaration, hosting amongst many basic concepts.

As this is my first post, I would like the opinions of experts on how to make this better

Thank you for your time.

Top comments (4)

Collapse
 
laika_lot profile image
Fearne York

I’ve just started learning JS in prep for a bootcamp, and even though I’ve gone over bits on freecodecamp.org and made notes it’s nice to see how someone else condenses them down to bite size chunks! Ty ✌️

Collapse
 
unkletayo profile image
Adetayo Akinsanya

Thanks Harry York, Glad you like it

Collapse
 
martinstreicher profile image
Martin Streicher

Nicely done.

Collapse
 
unkletayo profile image
Adetayo Akinsanya

Thank you, Martin