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

Javascript Essentials Notes

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Javascript Essentials Notes

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Complete JavaScript Beginner Notes (The Crucial 20% + More)

1. Variables

• Use let and const to store values.


• let can be updated; const cannot be changed once assigned.

let name = "Alice";


const age = 25;

Classwork: Create variables for your name, age, and school. Homework: Create variables for your 3
favorite foods and log them.

2. Data Types

• String: Text inside quotes


• Number: 5, 3.14, -10
• Boolean: true or false
• Array: List of items
• Object: Grouped data with keys

let isHappy = true;


let fruits = ["apple", "banana"];
let student = { name: "Sam", age: 10 };

Classwork: Create a variable for each data type. Homework: Create an object with your name, age, and
favorite color.

3. Operators

• Arithmetic: + , - , * , / , %
• Assignment: = , += , -=

let total = 5 + 3;
total += 2;

Homework: Write code to divide 100 by 5, then add 20 to the result.

1
4. Comparison Operators

• == : equal value
• === : equal value and type
• != , !== , > , < , >= , <=

let a = 5;
console.log(a == "5"); // true
console.log(a === "5"); // false

Homework: Compare your age to 18 using > , === .

5. Logical Operators

• && : AND
• || : OR
• ! : NOT

let isAdult = true;


let hasID = true;
console.log(isAdult && hasID); // true

Homework: Check if a student passed and has completed homework.

6. Type Conversion

• Convert strings to numbers and vice versa.

let numStr = "10";


let num = Number(numStr);

Homework: Convert "50" to a number, add 25.

7. String Methods

• .length , .toUpperCase() , .includes() , .slice()

let word = "JavaScript";


console.log(word.length);
console.log(word.toLowerCase());

2
Homework: Print the length of your name and convert it to uppercase.

8. Array Basics & Methods

• Arrays use square brackets []


• Methods: .push() , .pop() , .length

let colors = ["red", "blue"];


colors.push("green");

Homework: Create an array of 5 animals. Add and remove one.

9. Functions

• A block of reusable code

function greet(name) {
console.log("Hello, " + name);
}
greet("Sam");

Homework: Write a function that takes 2 numbers and adds them.

10. If/Else Statements

• Run different code based on conditions

let age = 17;


if (age >= 18) {
console.log("Adult");
} else {
console.log("Minor");
}

Homework: Create a program that checks if a number is even or odd.

11. Loops

• for , while , for...of

3
for (let i = 0; i < 5; i++) {
console.log(i);
}

let fruits = ["apple", "banana"];


for (let fruit of fruits) {
console.log(fruit);
}

Homework: List 10 numbers using a for loop.

12. Comments

• // for single line


• /* */ for multiple lines

// This is a comment
/* This
is multi-line */

Homework: Comment each line in one of your homework programs.

13. Basic Error Handling

• try...catch catches runtime errors

try {
let result = 10 / 0;
console.log(result);
} catch (e) {
console.log("Error happened!");
}

Homework: Try dividing by a string and catch the error.

14. Scope and var , let , const

• let and const are block-scoped


• var is function-scoped

4
let x = 10;
if (true) {
let x = 5;
console.log(x); // 5
}
console.log(x); // 10

Homework: Test scope by declaring variables in and outside a block.

FINAL PROJECT CHALLENGE

• Ask user for their name and age


• If age >= 18, print: "You can drive."
• Else, print: "Come back later."
• Use function , if , prompt , and console.log()

Ready to Learn More? Next topics: DOM Manipulation, Events, ES6 Features, Objects & Prototypes.

You might also like