diff --git a/README.md b/README.md index 69c7066..1cd39a9 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ This list contains the top essential questions that are frequently-asked during | 21 | [Describe event bubbling in JavaScript and browsers](#describe-event-bubbling-in-javascript-and-browsers) | Basic | | 22 | [Describe event capturing in JavaScript and browsers](#describe-event-capturing-in-javascript-and-browsers) | Basic | | 23 | [What is the difference between `mouseenter` and `mouseover` event in JavaScript and browsers?](#what-is-the-difference-between-mouseenter-and-mouseover-event-in-javascript-and-browsers) | Basic | -| 24 | [What is `'use strict';` in JavaScript for?](#what-is-use-strict-in-javascript-for) | Advanced | +| 24 | [What is `'use strict';` (strict mode) in JavaScript for?](#what-is-use-strict-strict-mode-in-javascript-for) | Advanced | | 25 | [Explain the difference between synchronous and asynchronous functions in JavaScript](#explain-the-difference-between-synchronous-and-asynchronous-functions-in-javascript) | Basic | | 26 | [What are the pros and cons of using Promises instead of callbacks in JavaScript?](#what-are-the-pros-and-cons-of-using-promises-instead-of-callbacks-in-javascript) | Intermediate | | 27 | [Explain AJAX in as much detail as possible](#explain-ajax-in-as-much-detail-as-possible) | Basic | @@ -276,13 +276,13 @@ This list contains a longer list of important JavaScript questions. Not all of t | 183 | [What are some tools and techniques for identifying security vulnerabilities in JavaScript code?](#what-are-some-tools-and-techniques-for-identifying-security-vulnerabilities-in-javascript-code) | Intermediate | | 184 | [How can you implement secure authentication and authorization in JavaScript applications?](#how-can-you-implement-secure-authentication-and-authorization-in-javascript-applications) | Advanced | | 185 | [Explain the same-origin policy with regards to JavaScript](#explain-the-same-origin-policy-with-regards-to-javascript) | Intermediate | -| 186 | [What is `'use strict';` in JavaScript for?](#what-is-use-strict-in-javascript-for) | Advanced | +| 186 | [What is `'use strict';` (strict mode) in JavaScript for?](#what-is-use-strict-strict-mode-in-javascript-for) | Advanced | | 187 | [What tools and techniques do you use for debugging JavaScript code?](#what-tools-and-techniques-do-you-use-for-debugging-javascript-code) | Intermediate | | 188 | [How does JavaScript garbage collection work?](#how-does-javascript-garbage-collection-work) | Advanced | | 189 | [Explain what a single page app is and how to make one SEO-friendly](#explain-what-a-single-page-app-is-and-how-to-make-one-seo-friendly) | Intermediate | | 190 | [How can you share code between JavaScript files?](#how-can-you-share-code-between-javascript-files) | Basic | | 191 | [How do you organize your code?](#how-do-you-organize-your-code) | Intermediate | -| 192 | [What are some of the advantages/disadvantages of writing JavaScript code in a language that compiles to JavaScript?](#what-are-some-of-the-advantagesdisadvantages-of-writing-javascript-code-in-a-language-that-compiles-to-javascript) | Advanced | +| 192 | [What are some of the advantages and disadvantages of using TypeScript and compile-to-JavaScript languages](#what-are-some-of-the-advantages-and-disadvantages-of-using-typescript-and-compile-to-javascript-languages) | Advanced | | 193 | [When would you use `document.write()`?](#when-would-you-use-documentwrite) | Advanced | @@ -497,13 +497,13 @@ All of these ways (` +``` + +Behavior: + +- **Parsing**: deferred. HTML parsing continues; the script does not block. +- **Execution**: runs after the document has finished parsing. Across multiple ` +``` + +## Which to use: a decision matrix + +| Script type | Use for | +| --- | --- | +| `` for the runtime and chunk entries. CRA itself is deprecated, and new projects should use Vite or Next.js. + +## Common bugs from the wrong attribute choice + +- **Analytics with `defer` instead of `async`.** `defer` waits for HTML parsing, so a third-party tag at the top of the page artificially extends `DOMContentLoaded`. Use `async` for any independent third-party tag. +- **App entry as `async` script.** If `app.js` and `vendor.js` are loaded with `async`, they can execute in any order. `app.js` may run before `vendor.js` finishes, which throws `ReferenceError` for the missing globals. Use `defer` (or modules) for app scripts. +- **`document.write` inside a `defer` or `async` script.** Browsers ignore `document.write()` calls from async or deferred scripts with a console warning: "A call to document.write() from an asynchronously-loaded external script was ignored." The script would need to be a regular blocking `