G1 Reporting CC210
G1 Reporting CC210
Group 1
Fundamentals
Arcenal, Arjay
Clanes, Renz Jerald
Paragon, Ronalyn
S o n a , Ky l a J a n e
Sub Topics
I. JavaScript
Fundamentals
II. Functions and Scope
III.
What is JavaScript?
JavaScript was introduced in 1995 as a
way to add programs to web pages in the
Netscape Navigator browser. The language has
since been adopted by all other major graphical
web browsers.
Function
function greet(user) {
return `Hi, ${user}!`;
}
console.log(greet("Sam")); // Output: Hi, Sam!
2.
Operators are symbols or keywords that perform
operations on one or more values (operands).
let x = 10;
let y = 5;
For Loop
Executes code a specific number of
times
output:
for (let i = 1; i <= 3; i++) { Iteration: 1
console.log("Iteration:", i); Iteration: 2
} Iteration: 3
While Loop
Repeats as long as a condition is
true.
output:
let i = 1;
Count: 1
while (i <= 3) {
Count: 2
console.log("Count:", i);
Count: 3
i++;
}
5. Functions
are reusable blocks of code that perform specific tasks.
They allow you to encapsulate logic, execute it when needed, and
even pass them around as values.
console.log(greet("Alice"))
;
6. Arrays
are reusable blocks of code that perform specific tasks.
They allow you to encapsulate logic, execute it when needed, and
even pass them around as values.
// Calling a method
person.greet(); // Output: Hello, I'm
Alice!
8. DOM Manipulation
<script>
document.getElementById("myButton").addEventListener("click", ()
=> {
alert("Button was clicked!");
});
</script>
output:
fetchData();
II. Functions and
Scope in JavaScript
Functions are blocks of reusable code that
perform tasks when called. They can accept inputs (parameters),
process them, and return outputs. Scope, on the other hand,
determines where variables and functions are accessible within your
code.
Functions in JavaScript
1. Function Declaration
2. Function Expression
3. Arrow Function
1. Function Declaration
A standard way to define a
function
function greet(name) {
return `Hello, ${name}!`;
}
1. Global Scope
2. Function Scope
3. Block Scope
4. Lexical Scope (Closure)
1. Global Scope
function showGlobal() {
console.log(globalVar); // Accessible
here
}
showGlobal(); // Output: I am
global
2. Function Scope
function localScope() {
let localVar = "I am local";
console.log(localVar); // Output: I am local
}
localScope();
// console.log(localVar); // Error: localVar is not
defined
3. Block Scope
if (true) {
let blockVar = "I exist only in this block";
console.log(blockVar); // Output: I exist only in this
block
}
// console.log(blockVar); // Error: blockVar is not
defined
4. Lexical Scope (Closure)
function innerFunction() {
console.log(outerVar); // Can access outerVar due to lexical scope
}
innerFunction();
}