JavaScript
JavaScript
JavaScript programs
A computer program is a list of ‘’instructions’’ to be ‘’executed’’ by a computer.
In a programming language, these programming instructions are called statements.
A JavaScript program is a list of programming statements.
JavaScript statements are composed of:
o values
o operators
o expressions
o keywords
o comments
Most JavaScript programs contain many JavaScript statements.
The statements are executed, one by one, in the same order as they are written
Semicolons (;)
Semicolons separate JavaScript statements
Add a semicolon at the end of each executable statement
When separated by semicolons, multiple statements on one line are allowed
Ending statements with semicolon is not required, but highly recommended
JavaScript Keywords
JavaScript statements often start with a keyword to identify the JavaScript action to be
performed
Some of the keywords are the following:
o var
declares a variable
o let
declares a block variable
o const
declares a block constant
o function
declares a function
o return
exits a function
JavaScript keywords are reserved words
Reserved words cannot be used as names for variables
JavaScript Syntax
JavaScript Syntax is the set of rules, how JavaScript programs are constructed
JavaScript Values
The JavaScript syntax defines two types of values:
o fixed values they are called literals
o variable values they are called variables
JavaScript Literals
The two most important syntax rules for fixed values are:
o Numbers are written with or without decimals
o Strings are text, written within double or single quotes
JavaScript Variables
In a programming language, variables are used to store data values
JavaScript uses the keywords var, let and const to declare variables
An equal sign ( = ) is used to assign values to variables
JavaScript Operators
JavaScript uses arithmetic operators ( + - * / ) to compute values
JavaScript Expressions
An expression is a combination of values, variables, and operators, which computes to a
value
The computation is called an evaluation
JavaScript Keywords
JavaScript keywords are used to identify actions to be performed
The let keyword tells the browser to create variables
The var keyword also tells the browser to create variables
JavaScript Comments
Not all JavaScript statements are ‘’executed’’
Code after double slashes // or between /* and */ is treated as a comment
Comments are ignored, and will not be executed
JavaScript Identifiers/Names
Identifiers are JavaScript names
Identifiers are used to name variables and keywords, and functions
A JavaScript name must begin with:
o a letter ( A-Z or a-z )
o a dollar sign ( $ )
o an underscore ( _ )
Subsequent characters may be letters, digits, underscores or dollar signs.
Numbers are not allowed as first character in names.
JavaScript
All JavaScript identifiers are case sensitive
o for example, the variables lastName and lastname, are two different variables