14
David Stotts Computer Science Department UNC Chapel Hill Introduction to Programming (in JavaScript)

Introduction to Programming (in JavaScript)

  • Upload
    jovita

  • View
    36

  • Download
    0

Embed Size (px)

DESCRIPTION

Introduction to Programming (in JavaScript). David Stotts Computer Science Department UNC Chapel Hill. The Big Six. 0. data ( types, simple information ) 1. data storage ( variables, assignment ) 2. data retrieval ( expressions, evaluation ) 3 . repetition ( loops ) - PowerPoint PPT Presentation

Citation preview

David StottsComputer Science Department

UNC Chapel Hill

Introduction to Programming

(in JavaScript)

0. data (types, simple information)

1. data storage (variables, assignment)

2. data retrieval (expressions, evaluation)

3. repetition (loops)

4. decision making (conditionals)

5. procedure abstraction (functions)

6. data abstraction (arrays)

7. objects: all-the-above, wrapped up

The Big Six

We can’t study data storage and retrieval without knowing what “data” is

Data the basic symbols and information that a computer manipulates

Data is why we write programs in the first place… we have questions, we want answers

Want information we have (input) turned into new information we need (output)

0. Databefore the big 6 there is an item 0

Input

information we have and want a program to work on…

we have to get it from the user and make it available to the program, in the computer memory

Output

the new info we expect the program to produce, to generate, to compute…

we have to get it out of the program and back to the user in a form the user can consume and employ

I/O is the term we use

Data

Von Nuemann Model of a Computer

computer

I/O

Cloud, etc.

Number 4, 10, -23, 729358, -414, 0

3.14159, -21.15, 7.0, 1101.1

5.3e7 17.336e-14

0.000031

integers and reals

DataJavaScript native types, “built in”

String

“tarheels” “x” “3.14159”

“(919) 555-1212”

“xp @ aol.com” “hola ! !”

“$ntko # &”

DataJavaScript native types, “built in”

Booleantrue, false (yes, no) are the only values

the basis for “logic”

DataJavaScript native types, “built in”

Number + - / * %4+5 9 23.4 + 9.3 32.7-2 * 7 -14 3.4 – 1.1 2.37/2 3.5 53 % 12 5 “mod”

Dataoperations on native types

Text + concat substring

“abc” + “123” “abc123” we call this concatenation

“abc”.concat(“123”) “abc123”

“tarheels”.substring(3) “heels” “tarheels”.substring(0,2) “tar”

Dataoperations on native types

Boolean && || ! true && true true ANDtrue && false falsefalse && false false

true || false true ORtrue || true truefalse || false false

!false true NOT!true false

Dataoperations on native types

Comparisons 5 < 8 true less than

17 <= 3.28 false less than or equal 21.4 > -34 true greater than 1.0 >= 1.1 false greater than or equal 12.3 == 2.8 false equal to 12.3 === 2.8 false equal to (safe)-3 != -3.1 true not equal to-3 !== -3.1 true not equal to (safe)

Dataoperations on native types

Comparisons work on strings too

“hello” < “world” true alpha order-ish

“bigfoot” > “big” true

“tar” == “tarheels” false

“tar” < “tarheels” true (it’s shorter)

“Upper” != “upper” true case matters

“upper” > “Upper” true (seems strange)

“5” > “4” true these are not numbers

“5” > “40” true remember… alpha order

Dataoperations on native types