Download presentation
Presentation is loading. Please wait.
1
An Introduction to JavaScript
MIS 2402 Jeremy Shafer Department of MIS Fox School of Business Temple University
2
Let’s talk about… Chapter 2 What does JavaScript do for us?
What were your key take-aways? Confusing items? Talk about languages: JavaScript vs HTML (General purpose vs. Domain-Specific languages)
3
Agenda Where does the JavaScript go?
An introduction to variables and syntax basics An introduction to primitive data types Using existing objects, properties, and methods
4
A block of JavaScript code
Where have we seen this before?
5
Where does JavaScript code go?
6
Example of an external JavaScript file
We would say here that the src attribute of the script tag provides a relative reference to the external JavaScript file.
7
Example of embedded JavaScript
The <script> </script> tag often appears in the <head> of the HTML document. But really it can go anywhere in the document!
8
JavaScript in the body of an HTML document
Here’s an example… two <script> tags mixed in with HTML
9
The basic syntax rules for JavaScript
JavaScript is actually pretty forgiving when it comes to missing semi-colons. Still, it is best to end each statement with a semi-colon.
10
Variables
11
Rules for naming variables
A list of reserved words are on page 59 of your textbook.
12
Valid identifiers in JavaScript
These are all valid identifiers. Can you think of some invalid identifier names?
13
Camel casing versus underscore notation
theCat theDog theHouse Versus… the_cat the_dog the_house
14
Naming recommendations for identifiers
15
JavaScript code with the comments highlighted
Discuss: Comments don’t change the way your code works. So, why comment at all?
16
The basic syntax rules for comments
17
JavaScript’s primitive data types
Discuss: Can you give me an example of each of these? Can you tell me what these are in your own words?
18
Examples of number values
19
Examples of string values
20
The two Boolean values
21
How to declare and assign a value to a variable in two statements
Notice the use of the var command here. We use var when creating a new variable.
22
How to declare and assign a value to a variable in one statement
23
Review of Terms
24
JavaScript’s arithmetic operators
WARNING! This is not a complete list. For a full list of arithmetic operators, you should refer to your textbook.
25
Example: Code that calculates sales tax
26
The concatenation operators for strings
Concatenation is a very common task!
27
How to concatenate a string and a number with the + operator
So far – we’ve talked about primitive data types, and operators to manipulate them. As we consider how to make JavaScript interact with browser, and an HTML document inside the browser, we need to start thinking about objects.
28
The window object JavaScript allows us to refer to the browser environment using something called the window object. Similarly, we can manipulate the current HTML document with the document object. In any programming language, objects have properties and methods. Methods represent things that the object can do (verbs) and properties represent values that the object has (nouns)
29
Common methods of the window object
30
A statement that calls the prompt() method with the object name omitted
31
One property of the window object
32
Two methods of the window object
33
Examples that use the parseInt() and parseFloat() methods
34
The same examples with the parse methods embedded in the alert() method
35
Two methods of the document object
36
Examples of the write() and writeln() methods
37
The output in a browser
38
Terms related to objects
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.