Javascript
JavaScript is a scripting language that allows to dynamically change the DOM and style of a page, either by querying more information from the backend as needed or by performing computations and changes based on user input directly in the web browser. - A Complete Overview of Front-End Development in 2021
see also
- You don’t need JavaScript for that
- Custom Switches
- Datalist, a native autosuggest
- A color picker that does more
- Accordions
- Dialog modals
Modifying The DOM
- change all the HTML elements in the page
- change all the HTML attributes in the page
- change all the CSS styles in the page
- remove existing HTML elements and attributes
- add new HTML elements and attributes
- react to all existing HTML events in the page
- create new HTML events in the page
window
- main object
document
- object accessible in javascript console (displayed as html content by the browser)html
-head
body
It is important to CACHE selectors in variables
Minimize repainting the DOM - can be seen by paint-flashing (chrome) see React
Events
Javascript (ECMAScript)
Browser Javascript console can be used as interactive environment, with history (up arrow).
- String can use double quote (“”) or single quote (‘’) and nest them with the other.
- 10 + “34” => “1034”
- 10 - “3” => 7
- “hello” - “bie” => NaN
- Undefined - variable not assigned
- null
=== / !== comparison
==
does type coercion when comparing - avoid
===
does not do type coercion
Variables
can start with _ or $
Template string / Template litterals
Array
support map, filter, reduce,
// ES10 .flat
Class (ES6)
Object (Legacy)
Object are reference types (non primitive type) meaning they are passed by reference (and are refeference themselves).
Primitive types are passed by value.
Functions
Helpers
value = prompt("input")
alert(value)
console.log("info")
Functions definition support closures. So it can be used to implement:
- currying:
const curriedMultiply = (a) => (b) => a + b;
- compose:
const compose = (f, g) => (a) => f(g(a));
Context vs Scope
Scope = visibility of variables. Context = depth of object tree we are in.
Symbol
try/catch
appears with ES10
Note
Parameters(a,b) vs Arguments(4,5)
Java script Environment
- Web API
- DOM
- AJAX
- Timeout
- Event Loop
- Callback Queue
- onClick, onLoad, onDone
- JS Engine
- Callstack
- Memory Heap
see also
- babeljs - translate new version of javascript syntax to legacy version
- codepen.io
- JS Fiddler