Day 1: Variables & Data Types
We learned about the three keywords used to declare variables in JavaScript: var
, let
, and const
.
var
β function-scoped, hoisted. β Not recommended due to unpredictable behavior.let
β block-scoped, can be reassigned. β Use this for most variables.const
β block-scoped, cannot be reassigned. β Use this by default if the value wonβt change.
We also explored JavaScript data types:
- String β e.g.,
"hello"
- Number β both integers and floats, e.g.,
42
,3.14
- Boolean β
true
orfalse
- undefined β declared but not assigned
- null β intentional absence of value
- Object β key-value pairs
- Array β ordered list of values
Example code:
// Variable declarations
let name = "Alice";
const age = 25;
var oldWay = "Avoid using var";
// Data types
let str = "Hello";
let num = 42;
let float = 3.14;
let isActive = true;
let unknown;
let empty = null;
let person = { name: "Bob", age: 30 };
let items = [1, 2, 3, "four"];
Day 2: Basic Operations & User Input
We practiced using JavaScript for basic arithmetic operations like addition, subtraction, multiplication, and division.
We also learned how to use the prompt()
method to get input
from the user, and how to convert string input into numbers using parseInt()
or parseFloat()
.
- + for addition
- - for subtraction
- * for multiplication
- / for division
Example code:
// Get input from user
const num1 = prompt("Enter first number:");
const num2 = prompt("Enter second number:");
// Convert to numbers
const a = parseInt(num1);
const b = parseInt(num2);
// Arithmetic operations
console.log("Addition:", a + b);
console.log("Subtraction:", a - b);
console.log("Multiplication:", a * b);
console.log("Division:", a / b);
Day 3: Functions, Scope & Conditions
We explored what functions are and how they are created using the function
keyword. We covered how to define and use
parameters and manipulate them within functions.
Additionally, we touched on the concept of variable scope and learned how to perform operations using user input through functions.
We also introduced if-else conditions and comparison operators to make decisions in our code.
Example code:
let input1, input2;
input1 = prompt("Enter value 1:");
input2 = prompt("Enter value 2:");
function addTwo(num1, num2) {
num1 = parseInt(num1);
num2 = parseInt(num2);
return num1 + num2;
}
function subTwo(num1, num2) {
num1 = parseInt(num1);
num2 = parseInt(num2);
return num1 - num2;
}
function multTwo(num1, num2) {
num1 = parseInt(num1);
num2 = parseInt(num2);
return num1 * num2;
}
function divTwo(num1, num2) {
num1 = parseInt(num1);
num2 = parseInt(num2);
return num1 / num2;
}
let result;
result = addTwo(input1, input2);
console.log(result);
result = subTwo(input1, input2);
console.log(result);
result = multTwo(input1, input2);
console.log(result);
result = divTwo(input1, input2);
console.log(result);
alert("You're an adult.");
Day 5: Concatenation & Operators
Today we explored different ways to concatenate strings in JavaScript, using
both the +
operator and modern template literals with backticks (`)
.
We also revisited the assignment operator =
,
and learned about comparison operators like ==
, !=
,
>
, <
, and their type-safe counterparts ===
and
!==
.
Understanding the difference between value comparison and type + value comparison is crucial when writing bug-free conditional logic.
Example code:
let firstName = "John";
let lastName = "Doe";
// Concatenation using +
let fullName = firstName + " " + lastName;
console.log(fullName);
// Concatenation using template literals
let greeting = `Hello, ${firstName} ${lastName}!`;
console.log(greeting);
// Comparison operators
console.log(5 == "5"); // true (value only)
console.log(5 === "5"); // false (value + type)
console.log(5 != "5"); // false
console.log(5 !== "5"); // true
// Assignment operator
let age = 25; // assigns 25 to age