Intro to JavaScript BLUETREX CanvaPpt
Intro to JavaScript BLUETREX CanvaPpt
Introduction to
JavaScript
AGOJO, LAIRA ANNE APDAL, JUSTINE CAÑAL, JOHN ROMEL EMBUIDO, RIAN JAKE GERONIMO, TAMARA
Topic Overview
JavaScript syntax and data types
Variables, functions, and control structures
DOM manipulation
Introduction to browser debugging tools
Syntax & Data Types
Variables
A temporary storage of numbers, expressions, and string literals
All variables have unique identifiers
If a variable is not declared, but given a value-- it will automatically be declared.
Using var
Using let Using var
Using const
var x = 5;
var y = 6;
var = x + y;
Try It!
Declaration of Variables
Ways to declare a variable:
Using var
Using let Using let
Using const
let x = 5;
let y = 6;
let z = x + y;
Try It!
Declaration of Variables
Ways to declare a variable:
Using var
Using let Using const
Using const
const x = 5;
const y = 6;
const z = x + y;
Try It!
Declaration of Variables
Variables declared with var are function-
scoped or globally-scoped. They can be re-
declared and updated within the same
Using var
scope.
var x = 5;
var y = 6;
var = x + y;
Try It!
Declaration of Variables
Variables declared with let are block-
scoped, meaning they only exist within the
block they are defined.
Using let
let x = 5;
let y = 6;
let z = x + y;
Try It!
Declaration of Variables
Variables declared with const are also
block-scoped but must be initialized at the
time of declaration and cannot be
Using const
reassigned.
const x = 5;
const y = 6;
const z = x + y;
Try It!
Declaration of Variables
DEMO
Defining Functions
SYNTAX Example
FUNCTION CALL
Function Parameters & Arguments
Functions can take parameters, allowing dynamic input when called.
Example:
Return Values from Functions
Using the return statement to send back values:
Example:
Function Expressions
Define functions that can be assigned to variables
Example:
Arrow Functions
A shorthand syntax introduced in ES6 that simplifies writing anonymous functions,
although they do not bind their own this.
Example:
Functions
DEMO
Control Structures
Without control structures, code would run sequentially, without conditional logic
or loops.
Types of Control Structures
A. CONDITIONAL STATEMENTS
Help execute code based on a condition.
Note: The break statement stops the execution of the next case. Without it, all cases will run until a
break is found.
Types of Control Structures
B. LOOPING STATEMENTS
Loops repeat a block of code while a specific condition is true.
DEMO
Introduction to browser debugging tools
Code Debugging:
the process of finding and fixing errors or bugs in the
source code of any software. When software does not work
as expected, computer programmers study the code to
determine why any errors occurred. They use debugging
tools to run the software in a controlled environment, check
the code step by step, and analyze and fix the issue.
Introduction to browser debugging tools
JavaScript Debugger:
All modern browsers have a built-in JavaScript debugger.
Built-in debuggers can be turned on and off, forcing errors
to be reported to the user.
With a debugger, you can also set breakpoints (places where
code execution can be stopped), and examine variables
while the code is executing.
Introduction to browser debugging tools
Setting Breakpoint:
In the debugger window, you can set breakpoints in the
JavaScript code.
At each breakpoint, JavaScript will stop executing, and let
you examine JavaScript values.
After examining values, you can resume the execution of
code (typically with a play button).
Introduction to browser debugging tools
DEMO
DOM Manipulation
Document Object Model
The DOM represents a web page’s structure in memory, allowing
programs to change the page’s content, style, or structure
HTML DOM METHODS
Property
A value that you can get or set (like changing the content of an HTML element)
Method
An action you can do (like add
or deleting an HTML element)
innerHTML Property
The most common way to
access an HTML element is to
use the id of the element. This
property is useful for getting or
replacing the content of HTML
elements
SELECTING ELEMENTS
Class Name
Tag Name
SELECTING ELEMENTS
Object Collections
EVENT LISTENER
addEventListener()
attaches an event handler to the specified element.
attaches an event handler to an element without overwriting
existing event handlers.
Syntax:
EVENT LISTENER