Lecture_8
Lecture_8
let x;
x = 6;
JavaScript Operators
• JavaScript uses arithmetic operators ( + - * / ) to compute values:
1. Using var
2. Using let
3. Using const
4. Using nothing
What are Variables?
• Variables are containers for storing data (storing data values).
• In this example, x, y, and z, are variables, declared with the var
keyword:
In this example, x , y , and z , are variables, declared with the let keyword:
Operator Description
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus (Division Remainder)
++ Increment
-- Decrement
JavaScript Assignment Operators
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 Logical Operators
Operator Description
|| logical or
! logical not
JavaScript Functions
• A JavaScript function is a block of code designed to perform a particular task.
A JavaScript function is executed when "something" invokes it (calls it).
JavaScript Function Syntax
• A JavaScript function is defined with the function keyword, followed by a
name, followed by parentheses ().
• Function names can contain letters, digits, underscores, and dollar signs
(same rules as variables).
• The parentheses may include parameter names separated by commas:
(parameter1, parameter2, ...)
The code to be executed, by the function, is placed inside curly brackets: {}
Why Functions?
• You can reuse code: Define the code once, and use it many times.
• You can use the same code many times with different arguments, to
produce different results.
JavaScript Events
Event Description
onmouseout The user moves the mouse away from an HTML element
Method Description