Professional Documents
Culture Documents
Javascript
HTML to define the content of web
pages
CSS to specify the layout of web
pages
JavaScript to program the behavior of
web pages
JavaScript
How do I get JavaScript?
Where can I download JavaScript?
Is JavaScript Free?
The <script> Tag
arithmetic operators ( + - * / )
to compute values:
assignment operator ( = )
to assign values to variables:
JavaScript Expressions
An expression is a combination of
values, variables, and operators, which
computes to a value.
The computation is called an evaluation.
JavaScript Identifiers / Names
Identifiers are JavaScript names.
Identifiers are used to name variables and
keywords, and functions.
The rules for legal names are the same in most
programming languages.
A JavaScript name must begin with:
A letter (A-Z or a-z)
A dollar sign ($)
Or an underscore (_)
Subsequent characters may be letters, digits,
underscores, or dollar signs.
JavaScript Variable
4 Ways to Declare a JavaScript
Variable:
Using var
Using let
Using const
Using nothing
JavaScript Identifiers
Operator Description
== equal to
=== equal value and equal type
!= not equal
!== not equal value or not equal type
> greater than
< less than
>= greater than or equal to
<= less than or equal to
? ternary operator
JavaScript Bitwise Operators
document.domConfig Obsolete. 3
document.embeds Returns all <embed> 3
elements
document.forms Returns all <form> 1
elements
document.head Returns the <head> 3
element
document.images Returns all <img> 1
elements
Property Description DOM
Type Example
ISO Date "2015-03-25" (The International
Standard)
Short Date "03/25/2015"
Long Date "Mar 25 2015" or "25 Mar 2015"
Get Date Methods
Method Description
getFullYear() Get the year as a four digit number
(yyyy)
getMonth() Get the month as a number (0-11)
getDate() Get the day as a number (1-31)
getHours() Get the hour (0-23)
getMinutes() Get the minute (0-59)
getSeconds() Get the second (0-59)
getMilliseconds() Get the millisecond (0-999)
getTime() Get the time (milliseconds since
January 1, 1970)
getDay() Get the weekday as a number (0-
6)
Date.now() Get the time. ECMAScript 5.
Set Date Methods
Method Description
setDate() Set the day as a number (1-31)
setFullYear() Set the year (optionally month and
day)
setHours() Set the hour (0-23)
setMilliseconds() Set the milliseconds (0-999)
setMinutes() Set the minutes (0-59)
setMonth() Set the month (0-11)
setSeconds() Set the seconds (0-59)
setTime() Set the time (milliseconds since
January 1, 1970)
Regular Expression Modifiers
perform case-insensitive more global searches
Modifier Description
Expression Description
[abc] Find any of the
characters between
the brackets
[0-9] Find any of the digits
between the brackets
(x|y) Find any of the
alternatives
separated with |
Metacharacters are characters with a
special meaning
Metacharacter Description
\d Find a digit
\s Find a whitespace
character
\b Find a match at the
beginning of a word
like this: \bWORD, or
at the end of a word
like this: WORD\b
\uxxxx Find the Unicode
character specified
by the hexadecimal
number xxxx
Quantifiers define quantities
Quantifier Description
n+ Matches any string
that contains at least
one n
n* Matches any string
that contains zero or
more occurrences of n
n? Matches any string
that contains zero or
one occurrences of n
JSON
{"employees":[
{ "firstName":"John", "lastName":"Doe"
},
{ "firstName":"Anna", "lastName":"Smit
h" },
{ "firstName":"Peter", "lastName":"Jone
s" }
]}
XML Example
<employees>
<employee>
<firstName>John</firstName> <lastName>Doe</
lastName>
</employee>
<employee>
<firstName>Anna</firstName> <lastName>Smith</
lastName>
</employee>
<employee>
<firstName>Peter</firstName> <lastName>Jones</
lastName>
</employee>
</employees>
JSON is Like XML Because