HTML CSS Bootstrap JavaScript jQuery MySQL PHP Data Mining

JavaScript Syntax

JavaScript syntax is the set of rules that defines how JavaScript code must be written. If statements are the instructions, syntax is the structure that makes those instructions valid and understandable to the browser.


Main Parts of JavaScript Syntax

Syntax controls how you write variables, values, operators, expressions, and statements. When your syntax is correct, the browser can read your code and run it properly. When your syntax is wrong, JavaScript throws an error and stops the code from working as expected.

When people talk about JavaScript syntax, they are usually talking about the basic building parts of code, such as values, operators, expressions, keywords, and names. Once you understand how these pieces fit together, writing JavaScript becomes much easier and much less confusing.


JavaScript Values

Values are the pieces of data JavaScript works with. They can be fixed values, such as numbers and strings, or variable values stored under a name.

10
"Hello"
true

In the example above, 10, "Hello", and true are all valid JavaScript values.


JavaScript Operators

Operators are symbols that tell JavaScript to perform an action. For example, = assigns a value, while + adds values together.

let x = 5;
let y = 6;
let total = x + y;

Here:

  • = stores a value in a variable
  • + adds two values together

JavaScript Expressions

An expression is any piece of code that produces a value. Expressions are often used inside statements.

5 + 6
"John" + " " + "Doe"

The first expression produces 11. The second produces the string "John Doe".

Note: A statement can contain an expression, but a statement and an expression are not exactly the same thing. A statement is the full instruction.

JavaScript Keywords

Keywords are reserved words that already have a special meaning in JavaScript. You use them to define how your code behaves.

let message = "Welcome";
if (message) {
    console.log(message);
}

In this code:

  • let creates a variable
  • if starts a condition
Warning: You cannot use JavaScript keywords as variable names. For example, names like let, if, or function are not allowed as identifiers.

JavaScript Identifiers

Identifiers are the names you give to variables, functions, and other code elements. JavaScript has a few naming rules:

  • Names can contain letters, digits, underscores, and dollar signs
  • Names must begin with a letter, underscore, or dollar sign
  • Names cannot start with a number
  • Names cannot be reserved keywords
let userName = "Rahim";
let _total = 100;
let $price = 25;

JavaScript Is Case Sensitive

JavaScript treats uppercase and lowercase letters as different characters. That means variable names must match exactly.

let lastName = "Islam";
let lastname = "Khan";

These are two different variables because lastName and lastname are not the same.

Tip: Use clear and consistent naming styles such as camelCase for variables. It makes your code easier to read and less likely to break because of case mistakes.

JavaScript Uses Unicode Characters

JavaScript supports Unicode, which means you can use many international characters in strings and text content. In practice, most developers still use simple and readable English-based variable names for better compatibility and teamwork.


Summary Table

Syntax Part What It Does
Values Represent data such as numbers, strings, and booleans
Operators Perform actions like assignment and addition
Expressions Produce a value from code
Keywords Reserved words with special meaning in JavaScript
Identifiers Name variables, functions, and other program elements
Case Sensitivity Makes uppercase and lowercase names different

Key Points to Remember

  • JavaScript syntax is the rule system that defines how code must be written
  • Values, operators, and expressions are core parts of JavaScript syntax
  • Keywords are reserved and cannot be used as variable names
  • Identifiers must follow JavaScript naming rules
  • JavaScript is case sensitive, so small letter changes matter
  • Clean syntax makes your code easier to read, debug, and maintain