DEV Community

Matt Gredler
Matt Gredler

Posted on • Updated on

JavaScript Syntax 101

JavaScript Syntax 101

At first glance, JavaScript can be overwhelming. There are many things to learn before one can understand what is written. The main way that seasoned developers can let less experienced individuals know what is going on are comments.

Comments

Comments are how developers let it be known what script does what. Not just to other people, but to themselves as well. Picking up Monday what you left off on Friday can be bewildering even to seasoned pros. Lets take a look some code courtesy of ibm.com/design. A few things to note:

  • There are two ways to denote comments; /* for multi-line comments and // for single line comments.

  • Comments are ignored when JavaScript is interpreted, they are there for human understanding.

Variables

Another component that is vital to the functionality of JavaScript are Variables. Variables are like boxes used to store things values in, you need the box but it is what it holds that is important. Variables keys are declared and as a constant but the value that it holds can be fluid.

There are three keywords used to declare a variable in JavaScript;

*Var, which stands for variable.

*Const, which denotes a constant, meaning the value is not fluid.

*Let, which has a fluid value.

Variables are expressed with and equal sign like so:

let x = 4;

Semicolons

Semicolons express the end to a statement. It means that that is the end of that expression. To keep files easy to read developers then go on to the next line, but that is not an absolute necessity. Forgetting to enter a semicolon will cause an error in your code.

These are the first three syntax components to know when you are starting out with JavaScript. You will see them every time you interact with JavaScript and will likely be the ones you will become most familiar with as your experience grows.

Top comments (0)