loading

JS Syntax

The set of guidelines used to design JavaScript programs is known as JavaScript syntax:

				
					// How to create variables:
var x;
let y;

// How to use variables:
x = 5;
y = 6;
let z = x + y;
				
			

JavaScript Values

Two categories of values are defined by the JavaScript syntax:

  • Set values
  • Variable amounts

Literals are defined as fixed values.

We refer to variable values as variables.

JavaScript Literals

For fixed values, the following two syntactic rules are extremely important:

  • Decimals can be used or not when writing numbers:
				
					10.50

1001
				
			
  • 2. Text placed in single or double estimates is called a string.
				
					"John Doe"

'John Doe'
				
			

JavaScript Variables

Variables are used in programming languages to store values of data.

To declare variables in JavaScript, use the keywords var, let, and const.

Values are assigned to variables using the equal sign.

x is defined as a variable in this example. Next, the number 6 is assigned (given) to x:

				
					let x;
x = 6;
				
			

JavaScript Operators

JavaScript computes values using the arithmetic operators (+ – * /):

				
					(5 + 6) * 10
				
			

JavaScript assigns values to variables using the assignment operator (=):

				
					let x, y;
x = 5;
y = 6;
				
			

JavaScript Expressions

A set of values, variables, and operators that add up to a value is called an expression.

We refer to the calculation as an evaluation.

For instance, 5 * 10 equals 50.

				
					5 * 10
				
			

Variable values can also be found in statements:

				
					x * 10
				
			

Different types of values, including strings and numbers, are possible.

For instance, “John” plus “” plus “Doe” equals “John Doe”:

				
					x * 10
				
			

JavaScript Keywords

Actions that need to be completed are identified by JavaScript keywords.

The browser is shown how to create variables using the let keyword:

				
					let x, y;
x = 5 + 6;
y = x * 10;
				
			

The browser is also directed to create variables by the var keyword

				
					var x, y;
x = 5 + 6;
y = x * 10;
				
			

Using let or var in these cases will get the same outcome.

var and let are two more topics you will cover in this tutorial.

JavaScript Comments

Not every statement in JavaScript is “executed”.

Comment is applied to code that comes after double slashes // or in between /* and */.

Remarks are not taken seriously and won’t be implemented:

Example

				
					let x = 5;   // I will be executed

// x = 6;   I will NOT be executed
				
			

A later chapter will cover comments in more detail.

JavaScript Identifiers / Names

JavaScript names are used as identifiers.

Functions, variables, and keywords are all named using identifiers.

In most computer languages, the rules related to legal names are the same.

JavaScript names have to start with:

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

The characters that follow can be dollar signs, underscores, letters, or numerals.

Note :

In names, numbers cannot appear as the initial character.

In this manner, JavaScript quickly differentiates between identifiers and integers.

JavaScript is Case Sensitive

All identifiers in JavaScript are case-sensitive. 

There are two separate variables, lastName and lastname:

				
					let lastname, lastName;
lastName = "Doe";
lastname = "Peterson";
				
			

LET or Let is not translated by JavaScript as the keyword let.

JavaScript and Camel Case

Programmers have combined several words into a single variable name in the past using a variety of techniques:

hyphens:

First name, last name, master card, inter-city.

In JavaScript, hyphens are not permitted. They’re kept aside for subtraction.

Underscore:

first_name, last_name, inter_city, master card.

Camel Case Upper (Pascal Case)

FirstName, LastName, InterCity, MasterCard.

Lower Camel Case:

JavaScript programmers typically begin their sentences with a lowercase letter (called camel case):

Master Card, InterCity, firstName, lastName.

JavaScript Character Set

Unicode character sets are used by JavaScript.

Almost every character, punctuation mark, and symbol in the world is covered by Unicode.

Share this Doc

JS Syntax

Or copy link

Explore Topic