Javascript: John Ryan B. Lorca Instructor I
Javascript: John Ryan B. Lorca Instructor I
What is JavaScript?
A client-side scripting language used to create interactive or animated content for the Internet, such as games or advanced financial applications
Variables
To declare a variable, you code:
var variable_name = value;
Output Statement
To display constant strings and variables:
On page
document.write(Hello World!); document.write(var_name);
On Message box
alert(Hello World!); alert(var_name);
String Concatenation
Symbol: plus (+) sign Usage Example:
var i = 5; alert (i + : Aloha!);
Arithmetic Operators
Addition var x = 5, y = 10, sum = 0; sum = x + y; Subtraction var x = 5, y = 10, diff = 0; diff = x - y;
Arithmetic Operators
Multiplication var x = 5, y = 10, prod = 0; prod = x * y; Division var x = 5, y = 10, quo = 0; quo = x / y;
Ternary Operators
Equal to Less than or equal to Greater than or equal to Not equal to == <= >= !=
Logical Operators
Used in making decisions (conjunction of ternary statements) Follows the truth table concept Symbols:
AND OR -> -> && ||
10
If Statement: Structure
if (<condition>) { <statements>; }
11
if Statement: Example
Example: if (x > 5) { alert(Hello!); }
12
13
14
15
16
19
20
21
22
23
24
25
26