JavaScript Fundamentals
1. Comments
Notes in code that do not run.
Example:
// single-line comment
/* multi-line comment */
2. Printing / Output
Use console.log() to display results.
Example:
console.log("Hello, world!");
3. Input
Use prompt() for basic user input (in browser).
Example:
let name = prompt("What’s your name?");
console.log("Hello, " + name);
4. Variables
Containers that store data values.
1 let → changeable variable
2 const → cannot be reassigned
3 var → older, avoid
Example:
let age = 16;
const pi = 3.14;
5. Data Types
Primitive Types:
1 Number → numeric values
2 String → text inside quotes
3 Boolean → true or false
4 Undefined → declared but not assigned
5 Null → intentional empty value
Reference Types:
1 Array → ordered list
2 Object → key-value pairs
6. Strings
Text inside quotes. Can use single, double, or backticks.
1 Concatenation: "Hello" + "World" = "HelloWorld"
2 Template literals: `` `Hello ${name}` ``
3 Properties & methods: .length, .toUpperCase(), .toLowerCase(), .includes(), .slice()
7. Conditionals (If Statements)
Make decisions in code.
Example:
if (score > 80) {
console.log("Great job!");
} else {
console.log("Keep practicing.");
}
8. Loops
Repeat actions without rewriting code.
1 For loop → repeat fixed times
2 While loop → repeat while condition true
Example:
for (let i = 0; i < 5; i++) { console.log(i); }
9. Arrays
Lists that store multiple values.
Example:
let fruits = ["apple", "banana", "cherry"];
fruits.push("orange");
10. Functions
Reusable blocks of code.
Example:
function greet(name) {
return `Hello, ${name}!`;
}
11. Objects
Key-value storage.
Example:
let student = { name: "Maya", age: 17, grade: "A" };
console.log(student.name);
12. Key Takeaways
1
2
3
4
Use let/const for variables
Learn primitive vs reference data types
Strings, numbers, and booleans are the building blocks
Conditionals and loops control logic
5 Arrays, objects, and functions organize data and code