Q
Which attribute should be used for loading external JavaScript files without blocking rendering in the <head> or <body> sections?

Answer & Solution

Answer: Option B
Solution:
The defer attribute is used to load external scripts asynchronously without blocking rendering, ensuring that HTML parsing and rendering are not delayed due to script loading and execution. The async attribute also loads asynchronously but doesn't guarantee execution order, which makes defer more suitable for scripts that depend on order.
Related Questions on Average

Which attribute can be used to make external JavaScript files load asynchronously in the <head> or <body> sections?

A). async

B). defer

C). sync

D). load

How can JavaScript be loaded asynchronously in the <body> section without blocking page rendering?

A). Using the defer attribute.

B). Using the async attribute.

C). Including scripts in the <head>.

D). Not possible in the <body>.

Using the defer attribute with an external JavaScript file in the <body> section means that the script:

A). Loads and executes after HTML parsing.

B). Loads synchronously with HTML parsing.

C). Loads and executes before HTML parsing.

D). Loads but doesn't execute.

Placing JavaScript at the end of the <body> section of an HTML document can result in:

A). Faster initial page rendering.

B). Slower overall page loading.

C). No impact on page performance.

D). Delayed execution of JavaScript.

Which of the following is a recommended practice for optimizing JavaScript performance?

A). Minify and concatenate scripts.

B). Include all scripts in the <head>.

C). Use synchronous loading for all scripts.

D). Load scripts without optimization.

When using an external JavaScript file in the <head> section with the defer attribute, when does it get executed?

A). After the HTML content is fully parsed.

B). Before the HTML content is parsed.

C). As soon as it starts loading.

D). After all other scripts in the <head>.

What happens if JavaScript code in the <head> section of an HTML document is not properly handled?

A). It may block rendering and cause delays.

B). It automatically moves to the <body>.

C). It gets executed twice.

D). It has no impact on the page.

Variables declared in the <body> section of an HTML document have what scope by default?

A). Local to the script or function.

B). Global throughout the document.

C). Limited to the <body> section.

D). Not accessible in JavaScript.

Which attribute is used to make an external JavaScript file load and execute after HTML parsing but before the DOMContentLoaded event in the <head> section?

A). async

B). defer

C). sync

D). load

What is the purpose of using the async attribute with an external JavaScript file?

A). To load the script asynchronously.

B). To defer script execution.

C). To block rendering until script loads.

D). To ensure script execution order.