5. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
What is a Programming Language?
A formalism or formal notion used to instruct a computer to
perform a computational task.
Roughly, a computational task is an abstract, mathematical in a
sense, task.
6. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
What is a Programming Language?
A formalism or formal notion used to instruct a computer to
perform a computational task.
Roughly, a computational task is an abstract, mathematical in a
sense, task.
Philosophical question: Is falling in love a computational task?
7. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
What is a Programming Language?
A formalism or formal notion used to instruct a computer to
perform a computational task.
Roughly, a computational task is an abstract, mathematical in a
sense, task.
Philosophical question: Is falling in love a computational task?
Surprisingly, computationalism—the view that mental states are
computational states—has many followers.
8. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
What is a Programming Language?
A formalism or formal notion used to instruct a computer to
perform a computational task.
Roughly, a computational task is an abstract, mathematical in a
sense, task.
Philosophical question: Is falling in love a computational task?
Surprisingly, computationalism—the view that mental states are
computational states—has many followers.
On the other hand, Jaak Panksepp asks: Could you compute me
an orgasm?
9. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
What is a Programming Language?
A formalism or formal notion used to instruct a computer to
perform a computational task.
Roughly, a computational task is an abstract, mathematical in a
sense, task.
Philosophical question: Is falling in love a computational task?
Surprisingly, computationalism—the view that mental states are
computational states—has many followers.
On the other hand, Jaak Panksepp asks: Could you compute me
an orgasm?
Back to business: Computers can calculate and enumerate and
that’s what we do with programming languages.
10. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
What is a Programming Language?
A formalism or formal notion used to instruct a computer to
perform a computational task.
Roughly, a computational task is an abstract, mathematical in a
sense, task.
Philosophical question: Is falling in love a computational task?
Surprisingly, computationalism—the view that mental states are
computational states—has many followers.
On the other hand, Jaak Panksepp asks: Could you compute me
an orgasm?
Back to business: Computers can calculate and enumerate and
that’s what we do with programming languages.
Niklaus Wirth did not like the term programming language.
14. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Characteristics of Programming Languages
How computational tasks are described?
By a sequence of commands? The language is imperative.
By objects and their interactions? The language is
object-oriented.
15. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Characteristics of Programming Languages
How computational tasks are described?
By a sequence of commands? The language is imperative.
By objects and their interactions? The language is
object-oriented.
By functions and their composition? The language is functional.
16. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Characteristics of Programming Languages
How computational tasks are described?
By a sequence of commands? The language is imperative.
By objects and their interactions? The language is
object-oriented.
By functions and their composition? The language is functional.
By a set of sentences in logical form? Then it is a logic
programming language
17. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Characteristics of Programming Languages
How computational tasks are described?
By a sequence of commands? The language is imperative.
By objects and their interactions? The language is
object-oriented.
By functions and their composition? The language is functional.
By a set of sentences in logical form? Then it is a logic
programming language
Specifying a programming language means to: describe its
syntax and its semantics.
18. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Characteristics of Programming Languages
How computational tasks are described?
By a sequence of commands? The language is imperative.
By objects and their interactions? The language is
object-oriented.
By functions and their composition? The language is functional.
By a set of sentences in logical form? Then it is a logic
programming language
Specifying a programming language means to: describe its
syntax and its semantics.
Syntax: the way we arrange “linguistic” elements in a program.
19. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Characteristics of Programming Languages
How computational tasks are described?
By a sequence of commands? The language is imperative.
By objects and their interactions? The language is
object-oriented.
By functions and their composition? The language is functional.
By a set of sentences in logical form? Then it is a logic
programming language
Specifying a programming language means to: describe its
syntax and its semantics.
Syntax: the way we arrange “linguistic” elements in a program.
Semantics: the computational effect of each structure.
45. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
What is Programming?
Programming is the mental activity by which we express the
solution to a given (mathematical) problem in some
programming language.
46. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
What is Programming?
Programming is the mental activity by which we express the
solution to a given (mathematical) problem in some
programming language.
The difficult part is to solve the problem with specific tools.
47. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
What is Programming?
Programming is the mental activity by which we express the
solution to a given (mathematical) problem in some
programming language.
The difficult part is to solve the problem with specific tools.
Programming is not something you learn by following a recipe or
a method.
48. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
What is Programming?
Programming is the mental activity by which we express the
solution to a given (mathematical) problem in some
programming language.
The difficult part is to solve the problem with specific tools.
Programming is not something you learn by following a recipe or
a method.
Programming is both a craft and a science.
49. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
What is Programming?
Programming is the mental activity by which we express the
solution to a given (mathematical) problem in some
programming language.
The difficult part is to solve the problem with specific tools.
Programming is not something you learn by following a recipe or
a method.
Programming is both a craft and a science.
It is a craft (or art!) because there are no rules of thumb that one
can follow to solve a problem.
50. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
What is Programming?
Programming is the mental activity by which we express the
solution to a given (mathematical) problem in some
programming language.
The difficult part is to solve the problem with specific tools.
Programming is not something you learn by following a recipe or
a method.
Programming is both a craft and a science.
It is a craft (or art!) because there are no rules of thumb that one
can follow to solve a problem.
A programmer is a scientist if mathematicians are scientists.
51. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
What is Programming?
Programming is the mental activity by which we express the
solution to a given (mathematical) problem in some
programming language.
The difficult part is to solve the problem with specific tools.
Programming is not something you learn by following a recipe or
a method.
Programming is both a craft and a science.
It is a craft (or art!) because there are no rules of thumb that one
can follow to solve a problem.
A programmer is a scientist if mathematicians are scientists.
Intuition plays a very important when solving a problem.
52. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
What is Programming?
Programming is the mental activity by which we express the
solution to a given (mathematical) problem in some
programming language.
The difficult part is to solve the problem with specific tools.
Programming is not something you learn by following a recipe or
a method.
Programming is both a craft and a science.
It is a craft (or art!) because there are no rules of thumb that one
can follow to solve a problem.
A programmer is a scientist if mathematicians are scientists.
Intuition plays a very important when solving a problem.
The implementation of a solution requires the knowledge of
common techniques and practicers.
64. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
What is JavaScript?
It is an object-oriented programming language initially designed
and implemented by Netscape.
The language is the most widely used language for client-side
scripting of web pages.
65. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
What is JavaScript?
It is an object-oriented programming language initially designed
and implemented by Netscape.
The language is the most widely used language for client-side
scripting of web pages.
HTML5 and all relatively older versions of HTML support tge
<script>
66. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
What is JavaScript?
It is an object-oriented programming language initially designed
and implemented by Netscape.
The language is the most widely used language for client-side
scripting of web pages.
HTML5 and all relatively older versions of HTML support tge
<script>
JavaScript can be used to make dynamic web pages.
67. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
What is JavaScript?
It is an object-oriented programming language initially designed
and implemented by Netscape.
The language is the most widely used language for client-side
scripting of web pages.
HTML5 and all relatively older versions of HTML support tge
<script>
JavaScript can be used to make dynamic web pages.
JavaScript and Java are object-oriented languages but that is
their only similarity.
75. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
A Complete Example
Here i a complete example:
<!DOCTYPE html>
<html> <head>
<meta charset="UTF-8">
<title>Example</title>
</head><body>
<script>
document.write("Hello, net!")
</script>
<noscript>No JavaScript support.</noscript>
<p>That's all, folks.</p>
</body> </html>
76. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
A Complete Example
Here i a complete example:
<!DOCTYPE html>
<html> <head>
<meta charset="UTF-8">
<title>Example</title>
</head><body>
<script>
document.write("Hello, net!")
</script>
<noscript>No JavaScript support.</noscript>
<p>That's all, folks.</p>
</body> </html>
Open your text-editor, type the code, save the file and open it with
your browser.
80. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Values
Numbers, that is, quantities like 41 or 3.14159.
Boolean (logical) values, that is, the values true and false.
Sequences of character like "Hello!" that are known as strings.
81. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Values
Numbers, that is, quantities like 41 or 3.14159.
Boolean (logical) values, that is, the values true and false.
Sequences of character like "Hello!" that are known as strings.
A string must be enclosed in either single or double quotation
marks, for instance, "John's girlfriend." or
'Mary came!'.
82. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Values
Numbers, that is, quantities like 41 or 3.14159.
Boolean (logical) values, that is, the values true and false.
Sequences of character like "Hello!" that are known as strings.
A string must be enclosed in either single or double quotation
marks, for instance, "John's girlfriend." or
'Mary came!'.
The value null, which denotes a no value.
83. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Values
Numbers, that is, quantities like 41 or 3.14159.
Boolean (logical) values, that is, the values true and false.
Sequences of character like "Hello!" that are known as strings.
A string must be enclosed in either single or double quotation
marks, for instance, "John's girlfriend." or
'Mary came!'.
The value null, which denotes a no value.
The value undefined, which denotes an undefined value.
87. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Variables
A variable is a name that is used to designate a value.
In mathematics we write 𝜋 to designate the number
3.1415926535897 ….
A variable is actually the name of some storage location where a
value is stored.
88. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Variables
A variable is a name that is used to designate a value.
In mathematics we write 𝜋 to designate the number
3.1415926535897 ….
A variable is actually the name of some storage location where a
value is stored.
Variables do not designate the same value but time passes may
designate a different value.
89. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Variables
A variable is a name that is used to designate a value.
In mathematics we write 𝜋 to designate the number
3.1415926535897 ….
A variable is actually the name of some storage location where a
value is stored.
Variables do not designate the same value but time passes may
designate a different value.
Think of a process that counts objects. In different times, it will
hold different values.
90. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Variables
A variable is a name that is used to designate a value.
In mathematics we write 𝜋 to designate the number
3.1415926535897 ….
A variable is actually the name of some storage location where a
value is stored.
Variables do not designate the same value but time passes may
designate a different value.
Think of a process that counts objects. In different times, it will
hold different values.
The first character of the name of a variable must be a letter
91. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Variables
A variable is a name that is used to designate a value.
In mathematics we write 𝜋 to designate the number
3.1415926535897 ….
A variable is actually the name of some storage location where a
value is stored.
Variables do not designate the same value but time passes may
designate a different value.
Think of a process that counts objects. In different times, it will
hold different values.
The first character of the name of a variable must be a letter
If there are more characters in a name they should be letters,
digits, or the symbol _ (underscore).
95. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Using Variables
A variable can be introduced with an assignment or a declaration.
Assignment: variable = value.
Declaration: var variable.
96. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Using Variables
A variable can be introduced with an assignment or a declaration.
Assignment: variable = value.
Declaration: var variable.
Thus the command x = 3 assigns the value 3 to variable x.
97. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Using Variables
A variable can be introduced with an assignment or a declaration.
Assignment: variable = value.
Declaration: var variable.
Thus the command x = 3 assigns the value 3 to variable x.
The command x = x + 1 assigns the current value of x plus 1
to variable x.
98. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Using Variables
A variable can be introduced with an assignment or a declaration.
Assignment: variable = value.
Declaration: var variable.
Thus the command x = 3 assigns the value 3 to variable x.
The command x = x + 1 assigns the current value of x plus 1
to variable x.
The command var y declares variable y and its value becomes
undefined.
99. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Using Variables
A variable can be introduced with an assignment or a declaration.
Assignment: variable = value.
Declaration: var variable.
Thus the command x = 3 assigns the value 3 to variable x.
The command x = x + 1 assigns the current value of x plus 1
to variable x.
The command var y declares variable y and its value becomes
undefined.
Find the final values of the various variables after these
commands have been executed.
x=4
y=6
z=2*x // * denotes multiplication
x=x+1
105. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Comparisons
valueA @ valueB, where @ is a comparison operator.
The standard comparison operators are:
== (equal to),
!= (not equal to),
< (less than),
106. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Comparisons
valueA @ valueB, where @ is a comparison operator.
The standard comparison operators are:
== (equal to),
!= (not equal to),
< (less than),
> (greater than),
107. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Comparisons
valueA @ valueB, where @ is a comparison operator.
The standard comparison operators are:
== (equal to),
!= (not equal to),
< (less than),
> (greater than),
<= (less than or equal to), and
108. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Comparisons
valueA @ valueB, where @ is a comparison operator.
The standard comparison operators are:
== (equal to),
!= (not equal to),
< (less than),
> (greater than),
<= (less than or equal to), and
>= (greater than or equal to).
109. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Comparisons
valueA @ valueB, where @ is a comparison operator.
The standard comparison operators are:
== (equal to),
!= (not equal to),
< (less than),
> (greater than),
<= (less than or equal to), and
>= (greater than or equal to).
Suppose that x = 5 and var y were just executed. Then,
110. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Comparisons
valueA @ valueB, where @ is a comparison operator.
The standard comparison operators are:
== (equal to),
!= (not equal to),
< (less than),
> (greater than),
<= (less than or equal to), and
>= (greater than or equal to).
Suppose that x = 5 and var y were just executed. Then,
x == 5 evaluates to true;
111. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Comparisons
valueA @ valueB, where @ is a comparison operator.
The standard comparison operators are:
== (equal to),
!= (not equal to),
< (less than),
> (greater than),
<= (less than or equal to), and
>= (greater than or equal to).
Suppose that x = 5 and var y were just executed. Then,
x == 5 evaluates to true;
x != 5 evaluates to false;
112. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Comparisons
valueA @ valueB, where @ is a comparison operator.
The standard comparison operators are:
== (equal to),
!= (not equal to),
< (less than),
> (greater than),
<= (less than or equal to), and
>= (greater than or equal to).
Suppose that x = 5 and var y were just executed. Then,
x == 5 evaluates to true;
x != 5 evaluates to false;
x < 5 evaluates to true;
113. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Comparisons
valueA @ valueB, where @ is a comparison operator.
The standard comparison operators are:
== (equal to),
!= (not equal to),
< (less than),
> (greater than),
<= (less than or equal to), and
>= (greater than or equal to).
Suppose that x = 5 and var y were just executed. Then,
x == 5 evaluates to true;
x != 5 evaluates to false;
x < 5 evaluates to true;
y == underfined evaluates to true;
114. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Comparisons
valueA @ valueB, where @ is a comparison operator.
The standard comparison operators are:
== (equal to),
!= (not equal to),
< (less than),
> (greater than),
<= (less than or equal to), and
>= (greater than or equal to).
Suppose that x = 5 and var y were just executed. Then,
x == 5 evaluates to true;
x != 5 evaluates to false;
x < 5 evaluates to true;
y == underfined evaluates to true;
x <= 5 evaluates to true.
117. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Arrays
An array is a special variable that can hold more than one value at
a time.
Each value is assigned to an element of an array and one can refer
to an array by its index.
118. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Arrays
An array is a special variable that can hold more than one value at
a time.
Each value is assigned to an element of an array and one can refer
to an array by its index.
119. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Arrays
An array is a special variable that can hold more than one value at
a time.
Each value is assigned to an element of an array and one can refer
to an array by its index.
To create an array, write the name of the array, the symbol =, and
the values that will be stored to the array in square brackets
separated by comma:
coffees = ["French Roast", "Columbian",
"Kona"]
120. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Arrays
An array is a special variable that can hold more than one value at
a time.
Each value is assigned to an element of an array and one can refer
to an array by its index.
To create an array, write the name of the array, the symbol =, and
the values that will be stored to the array in square brackets
separated by comma:
coffees = ["French Roast", "Columbian",
"Kona"]
To print the second element of this array, use the following
command:
document.writeln(coffees[0])
124. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Strings
A sequences of character like "Hello!".
A string must be enclosed in quotation marks: either single or
double quotation marks.
Strings consist of simple ASCII characters, escape sequences, or
Unicode characters.
125. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Strings
A sequences of character like "Hello!".
A string must be enclosed in quotation marks: either single or
double quotation marks.
Strings consist of simple ASCII characters, escape sequences, or
Unicode characters.
An escape sequence corresponds to a special character that
cannot be entered conventionally (e.g., the ESC key).
126. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Strings
A sequences of character like "Hello!".
A string must be enclosed in quotation marks: either single or
double quotation marks.
Strings consist of simple ASCII characters, escape sequences, or
Unicode characters.
An escape sequence corresponds to a special character that
cannot be entered conventionally (e.g., the ESC key).
Escape sequences consist of a backslash followed by a single
letter (e.g., b).
128. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Assignment Operators
An assignment operator stores the value that is on the right of the
operator to the storage location designated by the variable on
the left of the operator.
129. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Assignment Operators
An assignment operator stores the value that is on the right of the
operator to the storage location designated by the variable on
the left of the operator.
The basic assignment operators are:
130. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Assignment Operators
An assignment operator stores the value that is on the right of the
operator to the storage location designated by the variable on
the left of the operator.
The basic assignment operators are:
The expression x += y is shorthand for x = x + y.
131. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Assignment Operators
An assignment operator stores the value that is on the right of the
operator to the storage location designated by the variable on
the left of the operator.
The basic assignment operators are:
The expression x += y is shorthand for x = x + y.
Similarly, x -= y is shorthand for x = x - y;
132. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Assignment Operators
An assignment operator stores the value that is on the right of the
operator to the storage location designated by the variable on
the left of the operator.
The basic assignment operators are:
The expression x += y is shorthand for x = x + y.
Similarly, x -= y is shorthand for x = x - y;
x *= y is shorthand for x = x * y;
133. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Assignment Operators
An assignment operator stores the value that is on the right of the
operator to the storage location designated by the variable on
the left of the operator.
The basic assignment operators are:
The expression x += y is shorthand for x = x + y.
Similarly, x -= y is shorthand for x = x - y;
x *= y is shorthand for x = x * y;
x /= y is shorthand for x = x / y; and
134. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Assignment Operators
An assignment operator stores the value that is on the right of the
operator to the storage location designated by the variable on
the left of the operator.
The basic assignment operators are:
The expression x += y is shorthand for x = x + y.
Similarly, x -= y is shorthand for x = x - y;
x *= y is shorthand for x = x * y;
x /= y is shorthand for x = x / y; and
x %= y is shorthand for x = x % y.
139. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Arithmetic Operators
x % y Yields the reminder of the integer division of x by y.
x++ Yields the value of x and then increases the value of x by
one.
140. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Arithmetic Operators
x % y Yields the reminder of the integer division of x by y.
x++ Yields the value of x and then increases the value of x by
one.
x--
141. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Arithmetic Operators
x % y Yields the reminder of the integer division of x by y.
x++ Yields the value of x and then increases the value of x by
one.
x-- Yields the value of x and then decreases the value of x by
one.
142. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Arithmetic Operators
x % y Yields the reminder of the integer division of x by y.
x++ Yields the value of x and then increases the value of x by
one.
x-- Yields the value of x and then decreases the value of x by
one.
++x
143. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Arithmetic Operators
x % y Yields the reminder of the integer division of x by y.
x++ Yields the value of x and then increases the value of x by
one.
x-- Yields the value of x and then decreases the value of x by
one.
++x Increases the value of x by one and yields this new value.
144. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Arithmetic Operators
x % y Yields the reminder of the integer division of x by y.
x++ Yields the value of x and then increases the value of x by
one.
x-- Yields the value of x and then decreases the value of x by
one.
++x Increases the value of x by one and yields this new value.
--x
145. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Arithmetic Operators
x % y Yields the reminder of the integer division of x by y.
x++ Yields the value of x and then increases the value of x by
one.
x-- Yields the value of x and then decreases the value of x by
one.
++x Increases the value of x by one and yields this new value.
--x Decreases the value of x by one and yields this new value.
146. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Arithmetic Operators
x % y Yields the reminder of the integer division of x by y.
x++ Yields the value of x and then increases the value of x by
one.
x-- Yields the value of x and then decreases the value of x by
one.
++x Increases the value of x by one and yields this new value.
--x Decreases the value of x by one and yields this new value.
-x
147. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Arithmetic Operators
x % y Yields the reminder of the integer division of x by y.
x++ Yields the value of x and then increases the value of x by
one.
x-- Yields the value of x and then decreases the value of x by
one.
++x Increases the value of x by one and yields this new value.
--x Decreases the value of x by one and yields this new value.
-x Yields the opposite of x.
154. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Boolean Operators
x && y = true only if both x and y evaluate to true.
x || y = true if either x or y evaluate to true.
! x = true if x evaluates to false, true otherwise.
157. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
About Commands in General
A command is an instruction given by a user telling a computer to
do something.
Commands are put together by a programmer to achieve a
specific task.
158. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
About Commands in General
A command is an instruction given by a user telling a computer to
do something.
Commands are put together by a programmer to achieve a
specific task.
The basic commands of the language are:
159. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
About Commands in General
A command is an instruction given by a user telling a computer to
do something.
Commands are put together by a programmer to achieve a
specific task.
The basic commands of the language are:
Conditional commands: if...else and swicth.
160. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
About Commands in General
A command is an instruction given by a user telling a computer to
do something.
Commands are put together by a programmer to achieve a
specific task.
The basic commands of the language are:
Conditional commands: if...else and swicth.
Repetition commands: for, while, do...while, a labeled
command (used in repetition commands without being such a
command), the break command and the continue command.
161. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
About Commands in General
A command is an instruction given by a user telling a computer to
do something.
Commands are put together by a programmer to achieve a
specific task.
The basic commands of the language are:
Conditional commands: if...else and swicth.
Repetition commands: for, while, do...while, a labeled
command (used in repetition commands without being such a
command), the break command and the continue command.
Comments.
193. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
What is a Function?
A set is a collection of things (e.g., numbers, objects, people, etc.).
A function is a relation between the elements of two or more sets.
194. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
What is a Function?
A set is a collection of things (e.g., numbers, objects, people, etc.).
A function is a relation between the elements of two or more sets.
A function from a set 𝐴 to a set 𝐵 maps every element of 𝐴 to one
and only one element of 𝐵.
195. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
What is a Function?
A set is a collection of things (e.g., numbers, objects, people, etc.).
A function is a relation between the elements of two or more sets.
A function from a set 𝐴 to a set 𝐵 maps every element of 𝐴 to one
and only one element of 𝐵.
To define a function mathematically, we have to write something
like minus(𝑥) = −𝑥.
196. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
What is a Function?
A set is a collection of things (e.g., numbers, objects, people, etc.).
A function is a relation between the elements of two or more sets.
A function from a set 𝐴 to a set 𝐵 maps every element of 𝐴 to one
and only one element of 𝐵.
To define a function mathematically, we have to write something
like minus(𝑥) = −𝑥.
The letter 𝑥 is called a parameter, while the 5 in minus(5) is called
argument.
197. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
What is a Function?
A set is a collection of things (e.g., numbers, objects, people, etc.).
A function is a relation between the elements of two or more sets.
A function from a set 𝐴 to a set 𝐵 maps every element of 𝐴 to one
and only one element of 𝐵.
To define a function mathematically, we have to write something
like minus(𝑥) = −𝑥.
The letter 𝑥 is called a parameter, while the 5 in minus(5) is called
argument.
In computer jargon we say a function returns a value and we
mean the value that the function maps its argument.
200. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
New Functions
To define a function we first type the word function.
Then, the name of the function, which should be no different
than a variable name.
201. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
New Functions
To define a function we first type the word function.
Then, the name of the function, which should be no different
than a variable name.
Α sequence of parameters separated by comma surrounded by
parantheses.
202. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
New Functions
To define a function we first type the word function.
Then, the name of the function, which should be no different
than a variable name.
Α sequence of parameters separated by comma surrounded by
parantheses.
Τhe body of the function that is used to map the arguments to a
value or values. Typically, the body contains many commands
and is surrounded by curly brackets.
203. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
New Functions
To define a function we first type the word function.
Then, the name of the function, which should be no different
than a variable name.
Α sequence of parameters separated by comma surrounded by
parantheses.
Τhe body of the function that is used to map the arguments to a
value or values. Typically, the body contains many commands
and is surrounded by curly brackets.
Example:
function square(number){
return number*number
}
206. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
New Functions cont.
Command return interrupts the execution and forces the
function to map the argument to what follows this word.
We can use the function we defined in the previous slide as
follows:
x = square(3)
207. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
New Functions cont.
Command return interrupts the execution and forces the
function to map the argument to what follows this word.
We can use the function we defined in the previous slide as
follows:
x = square(3)
Obviously, this command assigns the number 9 to variable x
208. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
New Functions cont.
Command return interrupts the execution and forces the
function to map the argument to what follows this word.
We can use the function we defined in the previous slide as
follows:
x = square(3)
Obviously, this command assigns the number 9 to variable x
Functions in JavaScript can be recursive, that is, they can be
defined in terms of themselves.
209. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
New Functions cont.
Command return interrupts the execution and forces the
function to map the argument to what follows this word.
We can use the function we defined in the previous slide as
follows:
x = square(3)
Obviously, this command assigns the number 9 to variable x
Functions in JavaScript can be recursive, that is, they can be
defined in terms of themselves.
However, I will not discuss them here.
212. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Event Handling
An event is an action or occurrence that happens in the system
one is programming.
A system informs programs about events and so one can
program then to respond to them in some way if desired.
213. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Event Handling
An event is an action or occurrence that happens in the system
one is programming.
A system informs programs about events and so one can
program then to respond to them in some way if desired.
If a user clicks a button on a web page, a program might respond
to that action by displaying an information box.
214. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Event Handling
An event is an action or occurrence that happens in the system
one is programming.
A system informs programs about events and so one can
program then to respond to them in some way if desired.
If a user clicks a button on a web page, a program might respond
to that action by displaying an information box.
In order to define an event handler we need something that will
trigger an event.
215. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Event Handling
An event is an action or occurrence that happens in the system
one is programming.
A system informs programs about events and so one can
program then to respond to them in some way if desired.
If a user clicks a button on a web page, a program might respond
to that action by displaying an information box.
In order to define an event handler we need something that will
trigger an event.
When a user moves the mouse over an area, an event happens.
216. Introduction to
JavaScript
Syropoulos
Programming
Languages
Basics of
JavaScript
Expressions and
Operators
Basic Commands
Defining New
Functions
Finale
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Event Handling
An event is an action or occurrence that happens in the system
one is programming.
A system informs programs about events and so one can
program then to respond to them in some way if desired.
If a user clicks a button on a web page, a program might respond
to that action by displaying an information box.
In order to define an event handler we need something that will
trigger an event.
When a user moves the mouse over an area, an event happens.
To define an event handler: the name inside a tag followed by an
equal sign, followed by JavaScript code that will be invoked when
the event associated with the handler happens.