DEV Community

Cover image for JavaScript Syntax
Etulan
Etulan

Posted on

JavaScript Syntax

Rules are an important part of our lives and they serve to guide our actions and hopefully, keep us from committing crimes. That's why when picking up your editor to write some codes, you need to know the rules of JavaScript. Let's dive in!

JavaScript syntax is a set of rules that define a correctly structured JavaScript program.

JavaScript borrows most of its syntax from Java, C, and C++, but it has also been influenced by Awk, Perl, and Python. JavaScript is also case sensitive.

Syntax are further categorized as follows:

  1. Values
  2. Identifiers
  3. Operators
  4. Expressions
  5. Comments
  6. Keywords

Values

These are those things we use while executing JavaScript and they possess definite properties. JavaScript defines two types of values:

  • Fixed Values (Literals)
  • Variables Values (Variables)

Literals are fixed values that you provide in your code. Ther include string, array, boolean literals and more.

Variables are variable values that store data type.

Identifiers

An identifier is a sequence of characters in the code that identifies a variable, function, or property. (MDN Glossary)
They are part of the code itself and are case sensitive. They consist of letters, numbers, dollar and underscore symbols.

Operators

Operators are used in computing values. They operate on an operand and produce a result.
Alt Text

Expressions

An expression is any valid set of literals, variables, operators, and expressions that evaluates to a single value. The value may be a number, a string, or a logical value.
An Expression can give an evaluation
Alt Text

Or they can assign values to variables
Alt Text

Comments

In your Programming journey, you will have to share your script at some point or perhaps you wrote a code and you need to remember what the code does, or you need to debug by lines. This is where comments come in. Comments are not executed by JavaScript
Alt Text

Keywords

Have you ever entered a parking lot and you see the best spot reserved for the Head of Department? Exactly, keywords are reserved just for JavaScript meaning you shouldn't use them to name your variables or functions. Some examples are var, typeof, goto, do, while and so on. Can you name more?
Alt Text

If you made it to this point, then Congratulations! you know the rules. Want to know more? Feel free to learn more about each syntax as everything about them is not stated here. Remember to share your thought in the comment section.

Happy Coding!

Top comments (1)

Collapse
 
emmaglorypraise profile image
Glory Praise

Great introduction to Javascript!