Put it in body. Check it in the browser. Attributes go on the opening tag. Trap: wrong nesting or missing a required attribute. CSS can still style it — don’t pick a tag only because of default italics. Interview: name the tag, one attribute if it has a famous one (href, src, alt, for, type), one mistake."}}]}]}

<script> Tag — HTML Technical Interview Questions & Answers

Embeds or references executable JavaScript.

<script> Tag

  • Embeds or references executable JavaScript.
  • <script> is the <script> HTML element. HTML uses this tag so the browser (and screen readers) know what the piece is, not only how it looks.
  • Board: <script>…</script> Put it in body. Check it in the browser. Attributes go on the opening tag.
  • Trap: wrong nesting or missing a required attribute. CSS can still style it — don’t pick a tag only because of default italics.
  • Interview: name the tag, one attribute if it has a famous one (href, src, alt, for, type), one mistake.

Technical Interview Tip: <script>: the <script> HTML element. Example: <script>…</script>

Code Examples for <script> Tag

<script> Tag — working example

<!-- Prefer external + defer so HTML parses first -->
<script src="/app.js" defer></script>

<!-- Module scripts are deferred by default -->
<script type="module" src="/main.js"></script>

<script> Tag — defer runs after parse in order; async runs when ready (order not guaranteed); modules defer by default.

How to Explain <script> Tag to an Interviewer

What is the <script> tag?

the <script> HTML element <script>…</script>

One common mistake?

wrong nesting or missing a required attribute