JavaScript Syntax

  • JavaScript syntax determines the rules and format used to write any JavaScript code. The JavaScript code is written and organised for a program, guided by JavaScript syntax.

    JavaScript

    JavaScript Values

    JavaScript syntax has the following values:

    • Fixed values/ or literals and
    • Variable values or variables

    JavaScript Literals

    In JavaScript, literals are fixed values. The rules for writing these values are:

    1. Express numbers with or without a decimal point.
    2. Another value of literals is the string, which is a text written inside double or single quotes.
    HTML JavaScript

    JavaScript Variables

    In any programming language, a variable is a unit that stores data values. In JavaScript, keywords are used to specify a variable, such as let, var, or const. An equal sign ( = ) is used to assign values to JavaScript variables.

    HTML JavaScript

    JavaScript Operators

    In programming, JavaScript uses arithmetic symbols or operators (+, -, *, / ) to perform mathematical calculations.

    HTML JavaScript

    JavaScript Expressions

    A JavaScript expression is not a single value. It consists of values, variables, and operators, and the shown result has all these values. Computation in programming is also known as evaluation.

    HTML JavaScript

    Keep in mind that the JavaScript value can be either a number, a string, a group of numbers, or a combination of strings.

    JavaScript Keywords

    JavaScript identifies an action with the keyword written. So, JavaScript keywords declare a function or action to be performed.

    HTML JavaScript

    JavaScript Comments

    JavaScript statements contain the information about the functions that JavaScript will perform. However, not every JavaScript statement is meant to be executed. Any function that a developer does not wish to execute can be written as a JavaScript comment. Its code can be written in two ways: 

    • double slashes // or 
    • between /* and */

    The JavaScript program ignores any code that has these values.

    HTML JavaScript

    JavaScript Identifiers / Names

    In JavaScript, identifiers are its names. Variables, keywords, or functions in JavaScript are named by identifiers. Naming JavaScript values has a rule that the value should start with one of the following:

    • A letter (A-Z or a-z)
    • A dollar sign ($)
    • Or an underscore (_)

    No name in JavaScript begins with a number. This practice distinguishes JavaScript identifiers from numbers.

    JavaScript is Case Sensitive

    JavaScript identifiers are case sensitive. The variable’s last name and the last name of a name are not the same variable.

    HTML JavaScript

    JavaScript and Camel Case

    JavaScript lets you join multiple words to convert them into a single variable name. Programmers do it in the following ways: 

    1. Hyphens (first-name, second-name, etc.)

    Note that hyphens are used in JavaScript only for substractions.

    1. Underscore (first_name, second_name)
    2. Upper Camel Case or Pascal Case (FirstName, SecondName)
    3. Lower Camel Case (firstName, lastName)
    HTML JavaScript

    JavaScript Character Set

    In JavaScript, programmers use Unicode character sets. The Unicode character sets include all the characters, punctuation marks, and symbols that are universally used.

    HTML JavaScript
  • HTML
    CSS
    JS
  • Ad #1
    Ad #2
    Scroll to Top