Download presentation
Presentation is loading. Please wait.
Published byBrian Dorsey Modified over 9 years ago
1
Introduction to JavaScript CSc 2320 Fall 2014 Disclaimer: All words, pictures are adopted from “Simple JavaScript”by Kevin Yank and Cameron Adams and also from W3schools. Edited by Guoliang Liu, Only for Course CSc2320 at GSU CS Department
2
Resources Simple Javascript ◦ By kevin Yank and Cameron Adams W3Schools. ◦ http://www.w3schools.com/js/default.asp http://www.w3schools.com/js/default.asp
3
In this chapter Introduction to JavaScript Three Layers of Web Programming with JavaScript ◦ Running a JavaScript Program ◦ Statements ◦ Comments ◦ Variable ◦ Date types ◦ Operations
4
Introduction to JavaScript JavaScript is a Scripting Language ◦ Lightweight programming language ◦ Programming code embedded in HTML ◦ Can be executed by all modern web browsers Java and JavaScript ◦ Nothing like each other but some syntax. Standardized JavaScript: ◦ ECMAScript (newest 5.1)
5
Three Layers of Web The way to create pages in the way back. ◦ HTML, CSS, JavaScript all in one file.
6
Separation of Three Layers HTML: Content CSS: Presentation JavaScript: Behavior
7
The third layer: Behavior JavaScript: Writing Into HTML Output JavaScript: Reacting to Events JavaScript: Changing HTML Element ◦ JavaScript: Changing HTML Content ◦ JavaScript: Changing HTML Images JavaScript: Changing HTML Styles JavaScript: Validate Input Check out the examples here: ◦ http://www.w3schools.com/js/js_intro.asp http://www.w3schools.com/js/js_intro.asp
8
Programming with JavaScript Running a JavaScript Program Two ways to insert JavaScript code ◦ Internal: ◦ External:
9
JavaScript Statements In JavaScript each statement has to be separated by a new line or a semicolon. So, two statements could be written like this: Or Or both:
10
Comments Exactly the same with Java ◦ Single line: ◦ Multiple lines:
11
Variables: Store the data Declare a variable: ◦ var color; Declare and initialize: ◦ var color; ◦ color = “blue”; ◦ Or var color = “blue”; assignment operator (=).
12
Data Types for a variable Numbers ◦ integer or int. E.g., 3, 5, 100 ◦ Floating point number or float. E.g., 3.1415 ◦ var num = 5; ◦ var decimal = 10.2; Strings ◦ A series of characters coverd by ‘’ or “” var single = 'Just single quotes'; var double = "Just double quotes";
13
Data Types for a variable Booleans ◦ True or false; var lying = true; var truthful = false; Arrays ◦ good ways to store individual pieces of data
14
Data Types for a variable Arrays (cont.) ◦ More examples:
15
Data Types for a variable Associative arrays: ◦ Key-value in the array
16
Operations for variables JavaScript Arithmetic Operators Given y = 5;
17
Operations for variables JavaScript Assignment Operators
18
Operations for variables The + Operator Used on Strings
19
Exercise Write a simple JavaScript to pop up an alert. ◦ No need to submit. Try the following code and see the difference: ◦ var a=“string”; var b=“2”; var c = a+b; alert(c); ◦ var a=“string”; var b=2; var c = a+b; alert(c); ◦ Output the same or not? If not, why? ◦ No need to submit.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.