From 118a8b8e974963a1fc6fc6734968254162b78fdc Mon Sep 17 00:00:00 2001 From: Jet Hughes Date: Mon, 24 Oct 2022 18:48:10 +1300 Subject: [PATCH] vault backup: 2022-10-24 18:48:10 --- content/notes/javascript.md | 44 ++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/content/notes/javascript.md b/content/notes/javascript.md index cc15c4cf7..276cffd56 100644 --- a/content/notes/javascript.md +++ b/content/notes/javascript.md @@ -5,11 +5,53 @@ tags: - cosc203 --- -A scripting language to dynamically control websites. +An dynamically typed interpreted scripting language to dynamically control websites. # HTML DOM (Document object model) - JS can access and alter HTML elements - When a page loads it creates the DOM as a tree of objects +# Using js +Add inline, external or internal (script tags) js + +loading +- defer makes scripts run only after all scripts are loaded +- async scripts run as soon as they are loaded (no order guaranteed) + +# Events +Triggered by various things that happen on a webpage + +You can add an event listener to an element, which will trigger a function when that event occurs + +# Cookies +Used to store data on client machines + +Allows server to "remember users" + +# Limitations +- Cannot access client files +- Cannot establish a connection to any server except the one it came from (apart from re-directing to a new site) +- no multithreading +- cannot read history +- cannot open invisible windows + # Async +Allows running long tasks in background while browser remains responsive + +process +- Call function - returns a promise immediately +- When function is finished - we are notified and promise become a value + +callback: function passed to another function + +promise: object which represents the status of a function +- pending +- fulfilled -> .then +- rejected -> .catch +- settled (fulfilled or rejected) + +await: keyword within as async function which makes code wait at a point for a task to finish + +## Fetch +Used to request data from a server to update the page. Data is i \ No newline at end of file