CS 409 - Module 2

0.0(0)
studied byStudied by 0 people
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/40

flashcard set

Earn XP

Description and Tags

Introduction to Javascript

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

41 Terms

1
New cards

JavaScript

Most popular programming language and the programming language of the Web

2
New cards

JavaScript runs

  • In browsers (client-side)

  • On servers and other devices with JavaScript engines (e.g., Node.js)

3
New cards

Examples of engine codenames

  • V8 (Chrome, Opera)

  • SpiderMonkey (Firefox)

  • Trident, Chakra (Internet Explorer, Edge)

  • Nitro, SquirrelFish (Safari)

4
New cards

JavaScript Engine

  1. Parses the script (reads code)

  2. Compiles the script into machine code

  3. Runs the machine code efficiently

5
New cards

What Can In-Browser JavaScript Do?

  • Manipulate webpage content: add, change HTML and CSS styles.

  • Respond to user interactions: mouse clicks, key presses, pointer movement.

  • Perform asynchronous network requests (AJAX, COMET).

  • Manage cookies, interact with users via prompts and messages.

  • Store data locally on the client-side (localStorage)

6
New cards

What Cannot In-Browser JavaScript Do?

  • No arbitrary file system access (read/write/execute) on user’s device without explicit user action.

  • Cannot run or install programs on the host OS.

  • Access to hardware devices (camera, microphone) requires explicit user permission.

  • Restrictions on inter-window/tab communication from different origins (Same Origin Policy):

  • Cannot receive data from other domains without CORS (Cross-Origin Resource Sharing) permission.

  • Prevents malicious web pages from stealing private info or harming user data.

7
New cards

<script> Tag

Used to embed or link JavaScript code in HTML

8
New cards

Inline <script>

<script>

  alert("Hello, world!");

</script>

9
New cards

<script> Attributes

  • Type: Rarely used now; defaults to JavaScript

  • Language: Obsolete

10
New cards

External JavaScript Files

Use the src attribute, where external files are cached by browsers, improving speed

11
New cards

innerHTML (Displaying Output in JavaScript)

Modify HTML content of elements

12
New cards

document.write()

Writes HTML into the document. Use only for testing; overwrites the document if used after load

13
New cards

alert()

Shows a popup alert box

14
New cards

console.log()

Logs messages to the browser console (used for debugging)

15
New cards

Declaration and Assignment (Javascript Variables)

Containers for storing data values

16
New cards

var

Older, function-scoped

17
New cards

let

Block-scoped

18
New cards

const

Block-scoped, constant

19
New cards

Rules for naming variables

  • Can contain letters, digits, _, $

  • Must start with a letter, $, or _

  • Case-sensitive (y and Y are different)

  • Cannot use reserved keywords

20
New cards

Dynamic Typing

Variables can hold values of any type and can change type at runtime

21
New cards

Primitive Data Types

  • String

  • Number

  • Boolean

  • Undefined

  • Null

22
New cards

Arrays

Objects for storing multiple values

23
New cards

Adding a number and string (Type Coercion)

Results in string concatenation

24
New cards

typeof Operator

Used to check the type of a variable or expression

25
New cards

if Statement

Executes a block of code only if a specified condition is true

26
New cards

if Statement (Syntax)

if (expression) {

   // statements to execute if expression is true

}

27
New cards

if…else Statement

Provides an alternative block to execute when the condition is false

28
New cards

if…else Statement (Syntax)

if (expression) {

   // statements if true

} else {

   // statements if false

}

29
New cards

if…else if…else Statement

Used to test multiple conditions in sequence

30
New cards

if…else if…else Statement (Syntax)

if (expression1) {

   // code if expression1 is true

} else if (expression2) {

   // code if expression2 is true

} else if (expression3) {

   // code if expression3 is true

} else {

   // code if none are true

}

31
New cards

for Loop

Most compact form of looping in JavaScript

32
New cards

Three parts of the for Loop

  • Initialization: Set the starting value of the loop counter

  • Test Condition: A condition checked before each iteration; if true, loop executes; if false, loop ends

  • Iteration: Updates the counter (increment/decrement) after each loop cycle

33
New cards

for Loop (Syntax)

for (initialization; test condition; iteration) {

   // statements to execute

}

34
New cards

for...in Loop

Used to iterate over properties of an object through property name assigned to a variable in every iteration

35
New cards

for...in Loop (Syntax)

for (variable in object) {

   // statements to execute

}

36
New cards

Function

Reusable block of code designed to perform a particular task

37
New cards

Function Definition

Defined using the function keyword, followed by a unique name, optional parameters inside parentheses, and a block of statements inside {}

38
New cards

Function (Syntax)

function functionName(parameter1, parameter2, ...) {

   // statements to execute

}

39
New cards

Calling a Function

Use the name followed by parentheses

40
New cards

Function Parameters

Can accept multiple parameters separated by commas and be used inside the function for processing or output.

41
New cards

return Statement

Used to return a value from a function