WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

JavaScript Syntax


JavaScript is a programming language. Syntax rules define the structure of a language.

JavaScript syntax

JavaScript is a scripting language.

It's a lightweight but powerful programming language.

 

<script ...> 

JavaScript code 

</script>
The content label takes two critical properties − Language
Type

JavaScript Statements

JavaScript proclamations are formed of:

Values, Operators, Expressions, Keywords, what's more, Comments.


JavaScript Values

The JavaScript sentence structure characterizes two sorts of qualities: Fixed qualities and variable values.

Fixed values are called literals. Variable qualities are called variables.


JavaScript Literals

The most imperative guidelines for composing fixed qualities are:

Numbers are composed with or without decimals:

10.50

2001
Try it Yourself »

Strings are content, composed inside twofold or single quotes:

"Cena"

'Jhon'

JavaScript Variables

In a programming language, variables

In programming languages, variables are used to store data values.

JavaScript uses the keyword var to define variables, and uses equal signs to assign values to variables:

<script> var x;

x = 8;
</script> Try it Yourself »

JavaScript Operators

JavaScript utilizes a assignment operator ( = ) to assign qualities to factors:

var x = 6;
var y = 8;
Try it Yourself »

JavaScript utilizes arithmetic operators ( + - * /) to compute values:

(12 + 3) * 4
Try it Yourself »

JavaScript Expressions

An articulation is a mix of qualities, factors, and administrators, which processes to a value.

The calculation is called an evaluation.

For precedent, 6* 18 assesses to 108:

Expressions can likewise contain variable values:

x * 10

The qualities can be of different sorts, for example, numbers and strings.

For model, "John" + " " + "Doe", assesses to "John Doe":

"Moriss" + " " + "Son"


JavaScript Comments

Not all JavaScript articulations are "executed".

Code after twofold cuts // or between /* and */ is treated as a comment.

Comments are overlooked, and won't be executed:

<script> var x = 8;  /I will be executed

//var x = 3;   I will NOT be executed</script>
Try it Yourself »

JavaScript Identifiers

Identifiers are names.

In JavaScript, identifiers are utilized to name factors (and catchphrases, and capacities, and labels).

The rules for lawful names are much the equivalent in most programming languages.

In JavaScript, the principal character must be a letter, an underscore (_), or a dollar sign ($).

Subsequent characters might be letters, digits, underscores, or dollar signs.

JavaScript is Case Sensitive

All JavaScript identifiers are case sensitive

The factors lastName and lastname, are two diverse variables.

lastName = "Doe";
lastname = "Peterson";
Try it Yourself »

JavaScript does not translate VAR or Var as the watchword var.


JavaScript letter case

JavaScript is case sensitive.

When writing JavaScript statements, pay attention to whether the case switch key is turned off.

The function getElementById is different from getElementbyID .

Also, the variable myVariable is different from MyVariable .


JavaScript character set

JavaScript uses the Unicode character set.

Unicode covers all characters, including characters such as punctuation.


JavaScript keywords

JavaScript keywords identify actions to be performed.

Like any other programming language, JavaScript reserves some keywords for its own use.

The var keyword tells the browser to create a new variable:

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

JavaScript also retains some keywords that are not used in the current language version, but will be used in future JavaScript extensions.

Here are the most important reserved words (in alphabetical order) in JavaScript:

abstract else instanceof super
boolean enum int switch
break export interface synchronized
byte extends let this
case false long throw
catch final native throws
char finally new transient
class float null true
const for package try
continue function private typeof
debugger goto protected var
default if public void
delete implements return volatile
do import short while
double in static with