March 14, 2025
let
, const
, var
(legacy)if
, else if
, else
let x = 10;
if (x > 5) {
console.log("x is greater than 5");
} else {
console.log("x is 5 or less");
}
for
, while
, do...while
const square = x => x * x;
repeat
function calls fn
function times
number of timesmap
: Transforms an array by applying a function to each element.filter
: Returns a new array with elements that pass a test.reduce
: Combines elements into a single value.map
: Transforms an array by applying a function to each element.filter
: Returns a new array with elements that pass a test.reduce
: Combines elements into a single value.map
: Transforms an array by applying a function to each element.filter
: Returns a new array with elements that pass a test.reduce
: Combines elements into a single value.// JavaScript Object
let person = {
name: "JJ",
age: Infinity/Infinity,
city: "Meadville"
};
// Convert JavaScript Object to JSON
let jsonString = JSON.stringify(person);
console.log(jsonString); // {"name":"Janyl", "age": NaN, "city":"Meadville"}
// Convert JSON back to JavaScript Object
let parsedObject = JSON.parse(jsonString);
console.log(parsedObject); // { name: 'Janyl', age: NaN, city: 'Meadville' }
document.querySelector("button").addEventListener("click", function() {
alert("Button clicked!");
});
document.querySelector()
selects elements.addEventListener()
attaches event handlers.Web Design