JavaScript-Fundamentals-Study-Guide (1)
JavaScript-Fundamentals-Study-Guide (1)
1. Introduction to JavaScript
Operational Definition:
alert("Welcome to JavaScript!");
Output: A pop-up alert box appears with the message "Welcome to JavaScript!"
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.
Best Use Avoid using When value needs to When value must not
Case change change
Take note that:
Operational Definition:
Data types define the kind of values a variable can store. JavaScript has several built-in
data types.
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
+ Addition 5+3 8
- Subtraction 10 - 4 6
* Multiplication 6*3 18
/ Division 12 / 4 3
% Modulus (Remainder) 10 % 3 1
Comparison Operators
=== Strict equal to (checks value & type) 5 === "5" false
let a = 10, b = 5;
console.log(a + b, a - b, a * b, a / b, a % b);
Output: 15 5 50 2 0
5. Conditional Statements
Operational Definition:
Conditional statements allow the program to make decisions based on given conditions.
Example 1: If-Else Statement
console.log("You failed.");
switch (grade) {
case "A":
console.log("Excellent!");
break;
case "B":
console.log("Good job!");
break;
default:
console.log("Keep improving!");
Operational Definition:
Loops allow a block of code to run multiple times based on a specified condition.
For Loop
Count: 1
Count: 2
Count: 3
Count: 4
Count: 5
While Loop
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++;