|
bookmarks:
|
| main | ongoing | archive | private |
| Global Scope Variables declared Globally (outside any block or function) have Global Scope. Global variables can be accessed from anywhere in a JavaScript program. Variables declared with var, let and const are quite similar when declared outside a block. They all have Global Scope: var x = 1; // Global scope let y = 2; // Global scope const z = 3; // Global scope Example A variable declared outside a function, becomes GLOBAL. let carName = "Volvo"; // code here can use carName function myFunction() { // code here can also use carName } Function Scope All JavaScript functions have their own scope. Variables defined inside a function are n... jun 9 2026 ∞
jun 9 2026 +
jun 8 2026 ∞
jun 8 2026 +
jun 8 2026 ∞
jun 8 2026 +
jun 8 2026 ∞
jun 8 2026 +
jun 8 2026 ∞
jun 8 2026 +
jan 28 2019 ∞
jan 28 2019 + |
<button>Change color</button> const btn = document.querySelector("button"); function random(number) { return Math.floor(Math.random() * (number + 1)); } btn.addEventListener("click", () => { const rndCol = `rgb(${random(255)} ${random(255)} ${random(255)})`; document.body.style.backgroundColor = rndCol; });
the string "click", to indicate that we want to listen to the click event. Buttons can fire lots of other events, such as "mouseover" when the user moves their mous... jun 9 2026 ∞
jun 9 2026 +
jun 8 2026 ∞
jun 8 2026 +
jun 8 2026 ∞
jun 8 2026 +
jun 8 2026 ∞
jun 8 2026 +
jun 8 2026 ∞
jun 8 2026 + - Katy Perry - Connor McDavid - Avril Lavigne - Rhianna - Elliot Page - Garret Watts - Ian Somerhalder - Tyler Joseph - Phil Lester - Hayley Williams - Vic Fuentes jun 8 2026 ∞
jun 8 2026 + |
jun 9 2026 ∞
jun 9 2026 +
A non-breaking space is a space that will not break into a new line. Two words separated by a non-breaking space will stick together (not break into a new line). This is handy when breaking the words might be disruptive. Examples: § 1010 km/h10 PM
jun 9 2026 ∞
jun 9 2026 +
jun 8 2026 ∞
jun 8 2026 +
jun 8 2026 ∞
jun 8 2026 +
jun 8 2026 ∞
jun 8 2026 +
jun 8 2026 ∞
jun 8 2026 + |