CS114
INTRODUCTION TO JAVASCRIPT
1.0
5-1
Introduction to JavaScript •
Is a scripting language
•
Interpreted from within a browser.
•
Available in two formats : client-side JavaScript and serverside JavaScript.
•
It is an object-based language that comes with many built-in objects.
•
Is platform-independent as long as the browser is JavaScript-enabled.
•
Is designed to extend the capabilities of the Web application to provide user interactivity.
INTRODUCTION TO JAVASCRIPT
2.0
CS114
Keywords in JavaScript
3.0 Rules to follow when naming variables :
5-2
CS114
INTRODUCTION TO JAVASCRIPT
•
The name must begin with a letter or an underscore.
•
The rest of the name is made up of letters, numbers, or underscores.
•
Do not use the reserved words in JavaScript.
•
Avoid placing any spaces or punctuation in the name.
VALID
INVALID
mynumber
my number
student_no
student.no
male
*male
year2001
4.0
(period) (must start with a number) (must start with a number)
Operators in JavaScript
symbol = + * / % ++ -== != > < >= <= && ||
5.0
2001
(space)
description Assign values Addition Subtraction Multiplication Division Modulus returns the remainder Increments by one Decrements by one equals not equal to greater than less than greater than or equal to less than or equal to logical AND logical OR
Hello World Program
5-3
INTRODUCTION TO JAVASCRIPT
CS114
6.0 Window Alert
7.0 Window Prompt
5-4
CS114
INTRODUCTION TO JAVASCRIPT
8.0
Sample Codes 1
9.0
Sample Codes 2
5-5
INTRODUCTION TO JAVASCRIPT
10.0
Sample Codes 3
11.0
Sample Codes 4
CS114
5-6
CS114
INTRODUCTION TO JAVASCRIPT
5-7