Download presentation
Presentation is loading. Please wait.
2
CHAPTER 2 BASIC JAVASCRIPT INSTRUCTIONS
3
STATEMENTS
4
Each individual step in a script is known as a statement.
5
Each statement should end with a semi-colon.
6
document.write(‘Welcome!’);
SEMI-COLON
7
COMMENTS
8
You should use comments to explain what your code does
You should use comments to explain what your code does. They help you remember it and others understand it.
9
MULTI-LINE COMMENTS
10
/* Anything between these characters is a comment and will not be processed. */
11
/* Anything between these characters is a comment and will not be processed. */
12
SINGLE-LINE COMMENTS
13
// Anything after the two // forward slashes is also // a comment and will not // be processed.
14
// Anything after the two // forward slashes is also // a comment and will not // be processed.
15
VARIABLES
16
Scripts often need to store bits of information temporarily in order to achieve their tasks.
17
These bits of information - or data - are stored in variables.
18
DECLARING A VARIABLE
19
var quantity;
20
var quantity; KEYWORD
21
var quantity; VARIABLE NAME
22
ASSIGNING A VALUE TO A VARIABLE
23
quantity = 3;
24
quantity = 3; VARIABLE NAME
25
quantity = 3; ASSIGNMENT OPERATOR
26
quantity = 3; VALUE
27
DATA TYPES
28
JavaScript distinguishes between numbers, strings, and true or false values known as Booleans.
29
1
30
1 NUMBERS 0.75 NO QUOTES
31
2 1 NUMBERS 0.75 NO QUOTES
32
1 2 0.75 ‘Hi Ivy!’ NUMBERS STRINGS
NO QUOTES STRINGS ‘Hi Ivy!’ ENCLOSED IN QUOTES WHICH CAN BE SINGLE OR DOUBLE QUOTES, BUT MUST MATCH
33
3 1 2 0.75 ‘Hi Ivy!’ NUMBERS STRINGS
NO QUOTES STRINGS ‘Hi Ivy!’ ENCLOSED IN QUOTES WHICH CAN BE SINGLE OR DOUBLE QUOTES, BUT MUST MATCH
34
1 2 3 0.75 ‘Hi Ivy!’ true NUMBERS STRINGS BOOLEAN NO QUOTES
ENCLOSED IN QUOTES WHICH CAN BE SINGLE OR DOUBLE QUOTES, BUT MUST MATCH BOOLEAN true EITHER TRUE OR FALSE
35
ARRAYS
36
An array is a special type of variable
An array is a special type of variable. It doesn’t just store one value; it stores a list of values.
37
colors = [ ];
38
colors = [‘pink’ ];
39
colors = [‘pink’,’yellow’ ];
40
colors = [‘pink’,‘yellow’,‘green’];
41
colors = [‘pink’,‘yellow’,‘green’];
42
colors = [‘pink’,‘yellow’,‘green’];
43
colors = [‘pink’,‘yellow’,‘green’];
44
colors = [‘pink’,‘yellow’,‘green’];
45
ARITHMETIC OPERATORS
46
JavaScript uses mathematics to get some tasks done.
47
var width = 3;
48
var width = 3; var height = 2;
49
var width = 3; var height = 2; area = width * height;
50
var width = 3; var height = 2; area = width * height;
51
var width = 3; var height = 2; area = width * height;
52
var width = 3; var height = 2; area = width * height;
53
6
54
CONCATENATING STRINGS
55
There is just one string operator: the + symbol
There is just one string operator: the + symbol. It is used to join strings on either side of it.
56
var greeting = ‘Howdy ‘;
57
var greeting = ‘Howdy ‘; var name = ‘Molly’;
58
var greeting = ‘Howdy ‘; var name = ‘Molly’; var message = greeting + name;
59
var greeting = ‘Howdy ‘; var name = ‘Molly’; var message = greeting + name;
60
var greeting = ‘Howdy ‘; var name = ‘Molly’; var message = greeting + name;
61
var greeting = ‘Howdy ‘; var name = ‘Molly’; var message = greeting + name;
62
Howdy Molly
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.