0% found this document useful (0 votes)
2 views

JavaScript-Fundamentals-Study-Guide (1)

The document is a study guide on JavaScript fundamentals, covering key concepts such as variables, data types, operators, conditional statements, and loops. It explains how to declare variables, the differences between var, let, and const, and provides examples of various data types and their usage. Additionally, it outlines the functionality of operators and control flow structures in JavaScript programming.

Uploaded by

snupivanpelt
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

JavaScript-Fundamentals-Study-Guide (1)

The document is a study guide on JavaScript fundamentals, covering key concepts such as variables, data types, operators, conditional statements, and loops. It explains how to declare variables, the differences between var, let, and const, and provides examples of various data types and their usage. Additionally, it outlines the functionality of operators and control flow structures in JavaScript programming.

Uploaded by

snupivanpelt
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

JavaScript Fundamentals Study Guide

1. Introduction to JavaScript

Operational Definition:

JavaScript is a programming language that allows developers to make web pages


interactive. It runs in web browsers and can be used to create dynamic effects such as
animations, pop-ups, and form validations.

Example 1: Displaying an Alert Message

alert("Welcome to JavaScript!");

Output: A pop-up alert box appears with the message "Welcome to JavaScript!"

Example 2: Printing a Message in the Console


console.log("Hello, world!");

Output: The text "Hello, world!" appears in the browser's console.

2. Variables in JavaScript

Operational Definition:

Variables are used to store data values in a program. JavaScript provides three ways to
declare variables: var, let, and const.

Difference Between var, let, and const

Feature var let const

Scope Function-scoped Block-scoped Block-scoped

Hoisting Yes (initialized as Yes (but not Yes (but not


undefined) initialized) initialized)

Reassignment Yes Yes No

Best Use Avoid using When value needs to When value must not
Case change change
Take note that:

✔ Use const by default.


Use let if reassignment is needed.
⚠ Avoid var to prevent unexpected behavior/scoping concerns.

Example 1: Declaring and Using Variables

let studentName = "Alice";

console.log("Hello, " + studentName + "!");

Output: Hello, Alice!

Example 2: Using const for Constant Values


const PI = 3.1416;

console.log("The value of PI is " + PI);

Output: The value of PI is 3.1416

3. Data Types in JavaScript

Operational Definition:

Data types define the kind of values a variable can store. JavaScript has several built-in
data types.

Data Type Description Example

String Represents text "Hello"

Number Represents numeric values 42, 3.14

Boolean Represents true/false values true, false

Undefined Variable declared but not assigned a value let x;

Null Represents an empty or unknown value let y = null;

BigInt Represents very large integers 9007199254740991n

Symbol Unique identifier (used for object properties) Symbol("id")


Example 1: Different Data Types

let isStudent = true;

let age = 16;

let school = "Dumaguete Science High School";


console.log(isStudent, age, school);

Output: true 16 "Dumaguete Science High School"

Example 2: Undefined and Null

let x;

let y = null;

console.log(x, y);
Output: undefined null

4. Operators in JavaScript

Operational Definition:

Operators perform operations on variables and values. There are two main types:
arithmetic operators and comparison operators.
Arithmetic Operators

Operator Description Example Output

+ Addition 5+3 8

- Subtraction 10 - 4 6

* Multiplication 6*3 18

/ Division 12 / 4 3

% Modulus (Remainder) 10 % 3 1
Comparison Operators

Operator Description Example Output

== Equal to 5 == "5" true

=== Strict equal to (checks value & type) 5 === "5" false

!= Not equal 10 != 5 true

!== Strict not equal 10 !== "10" true

> Greater than 8>3 true

< Less than 5<2 false

Example 1: Arithmetic Operations

let a = 10, b = 5;
console.log(a + b, a - b, a * b, a / b, a % b);

Output: 15 5 50 2 0

Example 2: Comparison Operations

console.log(10 > 5, 8 === "8", 3 !== 3);

Output: true false false

5. Conditional Statements

Operational Definition:

Conditional statements allow the program to make decisions based on given conditions.
Example 1: If-Else Statement

let score = 85;

if (score >= 75) {


console.log("You passed!");
} else {

console.log("You failed.");

Output: You passed!


Example 2: Using Switch Case

let grade = "B";

switch (grade) {

case "A":
console.log("Excellent!");

break;

case "B":

console.log("Good job!");

break;

default:
console.log("Keep improving!");

Output: Good job!

6. Loops (Repetition Statements)

Operational Definition:
Loops allow a block of code to run multiple times based on a specified condition.

For Loop

Repeats a block of code a specified number of times.


for (let i = 1; i <= 5; i++) {

console.log("Count: " + i);


}
Output:

Count: 1
Count: 2

Count: 3

Count: 4
Count: 5

While Loop

Executes a block of code while a condition is true.

let x = 0;
while (x < 3) {

console.log("Hello");

x++;

Output:

Hello
Hello

Hello

Do-While Loop

Runs the block of code at least once, then repeats while the condition is true.

let y = 0;

do {
console.log("This runs at least once.");

y++;

} while (y < 3);


Output:

This runs at least once.


This runs at least once.
This runs at least once.

You might also like