- OBJECTS
- Basics
- Reference
- Methods
- Constructor
- FUNDAMENTALS
- Hello World
- Code Structure
- Use Strict
- Variables
- Data Types
- Type Conversions
- Maths
- Comparitions
- Conditional
- Loops
- Functions
- TESTING
- Mocha
- Nested Describe
- TYPES
- Primitives
- Numbers
- Strings
- Arrays
- Json
- DESIGN PATTERN
- Observer Pattern
- CLASSES
- Constructor
- Binding
- Inheritance
JAVASCRIPT PAGES -
LEVEL 1
Life cycle
The lifecycle of an HTML page has three events: DOMContentLoaded / Window Load / Window Unload – the user is leaving the page1) DOMContentLoaded
The browser fully loaded HTML, and the DOM tree is built. The DOMContentLoaded event happens on the document object. When the browser processes an HTML-document and comes across a script tag, it needs to execute before continuing building the DOM.Javascript
document.addEventListener("DOMContentLoaded", ready);
function ready()
{
console.log('DOM is ready!');
}
Javascript
document.addEventListener("DOMContentLoaded", function(){
console.log('DOM is ready!');
});
console.log('DOM not ready yet!');
// DOM not ready yet!
// DOM is ready
2) Window load
All the external resources are loaded (images, styles). The load event on the window object triggers when the whole page is loaded.
window.onload = function()
{
console.log('Page loaded!');
}
console.log('Page not loaded yet!');
//Page not loaded yet!
//Page loaded