Javascript (Self Learn)
13/08/2025
Parameter & Argument (Value)Parameter is like a placeholder variable inside a function that waits for you to give it a value when the function runs. Think of it like a labeled cup, the cup is empty when you define the function, but when you call the function, you pour in an actual drink (value).
Variables
- Variables stores data
Use:
let → changeable
const → fixed value
var → old way, AVOID it for now ❌❌❌
Use:
let → changeable
const → fixed value
var → old way, AVOID it for now ❌❌❌
Figure 1.2 Variables
Data Types
1. String → "Hello"
2. Number → 42, 3.14
3. Boolean → true / false
4. Array → ["apple", "banana"]
5. Object → { name: "Wing", age: 20 }
6. null & undefined → “nothing” or “not set”
document:
- Refers to the whole HTML page (the DOM - Document Object Model).
- It’s how JavaScript can “see” and interact with HTML elements.
getElementById("myBtn"):
- Looks inside the HTML document and finds the element with the id="myBtn".
Example in HTML: <button id="myBtn">Click me</button>
.addEventListener("click", ... ):
- Tells the element: “When this specific event happens, run some code.”
- "click" means we’re listening for a mouse click.
- Other events could be "mouseover", "keydown", "submit", etc.
function() { alert("Button clicked!"); }:
- This is an anonymous function (it has no name).
- It’s the code that will run when the button is clicked.
- alert("Button clicked!") pops up a message box on the screen.
1. String → "Hello"
2. Number → 42, 3.14
3. Boolean → true / false
4. Array → ["apple", "banana"]
5. Object → { name: "Wing", age: 20 }
6. null & undefined → “nothing” or “not set”
Functions
- Functions package code to run later
Figure 1.3 Functions
If Statements
- Helps in decision making
- Helps in decision making
Figure 1.4 If Statements
Button
- example of button with javascript
Figure 1.5 getElementByID, addEventListener
document:
- Refers to the whole HTML page (the DOM - Document Object Model).
- It’s how JavaScript can “see” and interact with HTML elements.
getElementById("myBtn"):
- Looks inside the HTML document and finds the element with the id="myBtn".
Example in HTML: <button id="myBtn">Click me</button>
.addEventListener("click", ... ):
- Tells the element: “When this specific event happens, run some code.”
- "click" means we’re listening for a mouse click.
- Other events could be "mouseover", "keydown", "submit", etc.
function() { alert("Button clicked!"); }:
- This is an anonymous function (it has no name).
- It’s the code that will run when the button is clicked.
- alert("Button clicked!") pops up a message box on the screen.





Comments
Post a Comment