In JavaScript, constructors can share methods via their prototype objects so that every instance created from the constructor gains access without duplicating code. For example, to provide all instances of a constructor with an age calculation method: function Human(yearBorn) { this.yearBorn = yearB...
Conditional randering in React is the process of displaying specific UI elements based on certain criteria, such as application state, user permissions, or data availability. Unlike template-based frameworks with built-in directives, React leverages standard JavaScript logic to handle these scenario...
Framework design involves constant trade-offs between different approaches. When designing a framework, its modules are interconnected and influence eachother. Designers must understand the framework's overall direction to make informed decisions about module architecture. Similarly, learners should...
Location Interface Direct access to the current document's address bar is provided through the window.location property. This interface exposes methods and attributes for reading protocol information, server addresses, and executing page redirects. <!DOCTYPE html> <html lang="en"&...
The three core technologies of frontend development are HTML, CSS, and JavaScript. 1. HTML - Web Page Content 1.1 Concept HyperText Markup Language (HTML) is a standard markup language used to create web pages. It is not a programming language, but a markup language composed of various tags. It can...
Defining Classes in ES5 In the ES5 standard, classes are implemented using constructor functions. There are several patterns for assigning properties and methods. Instance-Level Definitions Methods and properties can be defined directly inside the constructor function. While this allows for easy par...
Setting Cookies To create a cookie, use the following function: function createCookie(name, value, daysToExpire = 1) { const expirationDate = new Date(); expirationDate.setTime(expirationDate.getTime() + daysToExpire * 24 * 60 * 60 * 1000); const host = window.location.host; const hostParts = host.s...
To test your understanding of async/await behavior in the JavaScript event loop, try these two similar snippets first: async function runFirstTask() { await new Promise((resolve, reject) => { resolve(); }); console.log('A'); } runFirstTask(); new Promise((resolve) => { console.log('B'); resolv...
Hyperlinks utilizing target="_blank" attributes create bidirectional browsing context connections that expose the originating document to potnetial manipulation. When a new tab or window opens via this method, the JavaScript window.opener property in the destination page maintains a refere...
1. Prototype Chianing Inheritance (Simplest Approach) function Parent(name) { this.name = name; this.favoriteSports = ['basketball', 'football']; this.location = { country: 'China', city: 'Jiangsu' }; } function Child(name) { this.greet = function() { console.log('I am a child'); }; } Child.prototyp...