0% found this document useful (0 votes)
23 views73 pages

CENG374 Lesson9 PDF

The document discusses JavaScript concepts like variables, data types, operators, functions and more. It provides examples and explanations of JavaScript syntax and features. Key topics covered include variable declaration, assignment, arithmetic and comparison operators, strings, numbers, booleans, arrays, objects, functions, parameters, return values and scope.

Uploaded by

uzainab460
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views73 pages

CENG374 Lesson9 PDF

The document discusses JavaScript concepts like variables, data types, operators, functions and more. It provides examples and explanations of JavaScript syntax and features. Key topics covered include variable declaration, assignment, arithmetic and comparison operators, strings, numbers, booleans, arrays, objects, functions, parameters, return values and scope.

Uploaded by

uzainab460
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 73

CENG374

Internet
Programming
LESSON 9
Client-Side Technologies:
JavaScript and XHTML
Documents
JavaScript Output
JavaScript Display Possibilities

JavaScript can "display" data in different ways:

● Writing into an HTML element, using innerHTML.


● Writing into the HTML output using document.write().
● Writing into an alert box, using window.alert().
● Writing into the browser console, using console.log().
JavaScript Statements
JavaScript Variables
JavaScript Variables
JavaScript Variables
JavaScript Variables
JavaScript Variables
When to Use var, let, or const?
JavaScript Let
JavaScript Let
Global Scope
JavaScript Const
JavaScript Const
When to use JavaScript const?
JavaScript Operators
JavaScript Operators
Types of JavaScript Operators
● Arithmetic Operators
● Assignment Operators
● Comparison Operators
● String Operators
● Logical Operators
● Bitwise Operators
● Ternary Operators
● Type Operators
JavaScript Arithmetic
JavaScript Assignment
JavaScript Assignment
JavaScript Assignment
JavaScript Assignment
JavaScript Data Types
JavaScript Data Types Examples
JavaScript Data Types Examples
JavaScript Data Types Examples

Output
JavaScript Data Types Examples
JavaScript Data Types Examples

Output
JavaScript Data Types Examples
JavaScript Data Types Examples

Output
JavaScript Data Types Examples
JavaScript Data Types Examples

Output
JavaScript Types are Dynamic
JavaScript Strings
JavaScript Strings

Output
JavaScript Strings
JavaScript Numbers
Output
Exponential Notation
Note
JavaScript BigInt
JavaScript Booleans
JavaScript Arrays

Array indexes are zero-based, which means the first item


is [0], second is [1], and so on.
JavaScript Objects

The object (person) in the example above has 4 properties:


firstName, lastName, age, and eyeColor.
The typeof Operator
Undefined
Empty Values
JavaScript Functions
JavaScript Functions

Output
JavaScript Function Syntax
Function Invocation
The code inside the function will execute when
"something" invokes (calls) the function:

● When an event occurs (when a user clicks a button)


● When it is invoked (called) from JavaScript code
● Automatically (self invoked)
Function Return
Function Return

Output
Why Functions?
● With functions you can reuse code
● You can write code that can be used many times.
● You can use the same code with different arguments, to
produce different results.
The () Operator
The () Operator
Output
The () Operator
Accessing a function with incorrect parameters can return an
incorrect answer:
The () Operator
Accessing a function with incorrect parameters can return an
incorrect answer:

Output
The () Operator
Accessing a function without () returns the function and not the
function result:
The () Operator
Accessing a function without () returns the function and not the
function result:

Output
Functions Used as Variable Values
Local Variables
Local Variables

Output
Questions
Question 1
Execute the function named myFunction.
Answer 1
Question 2
Use comments to describe the correct data type
of the following variables:
Answer 2
Question 3
Use the correct assignment operator that will result in x being 15
(same as x = x + y).
Answer 3
Question 4
What will be the output of the following code snippet?
Question 5
What will be the output of the following code snippet?
Thanks for listening…

You might also like