01Which tag and attribute are used to include JavaScript in an HTML page?
The <SCRIPT> tag, with its Language attribute set to "JavaScript".
02What does document.write() do?
It is a JavaScript function that inserts the given text into the body section of the web page — document refers to the body section itself.
03Why must a function be called even after it is defined?
Defining a function only stores its instructions — it does not run automatically. It executes only when called by its name followed by parentheses.
04Name the three basic data types in JavaScript.
Number, String, and Boolean.
05What keyword declares a variable in JavaScript, and how does that differ from C++?
The keyword var declares every variable, regardless of the type of value it will hold — unlike C++, which uses a different keyword (int, float, char, etc.) for each type.
06What value does a declared-but-unassigned variable hold, and what does typeof() do?
It holds the special value undefined. typeof() is a built-in function that reports the current data type of a variable.
07How does the + operator behave differently with strings versus numbers?
Between two numbers, + adds them arithmetically. If either operand is a string, both are treated as strings and + concatenates them instead.
08Why is the Number() function often needed when processing text box input?
Text box content is always treated as a string by default. Number() converts that string into a true number type so arithmetic operators add rather than concatenate the values.
09List the control structures covered in this chapter.
if and if–else, switch, the for loop, and the while loop — all used exactly as they are in C++.
10What does isNaN() check, and why is it useful for validation?
It returns true if the given value is NOT a number. It's useful for checking whether a user has typed a number into a field that expects one, before further processing.
11How is a web page element accessed from JavaScript, and why must it be named?
Using document.formName.elementName.value. An element with no Name attribute cannot be referenced from JavaScript at all.
12What does onClick= "functionName()" do when written inside an INPUT tag?
It calls that function whenever the user clicks the element — one of several event attributes (along with onMouseEnter, onMouseLeave, onKeyDown, onKeyUp) that can trigger a JavaScript function.
13What does the selectedIndex property of a SELECT element give you?
The position (starting from 0) of the currently chosen OPTION in a drop-down list.
14What are the three places a script can be placed, and what's the advantage of an external .js file?
Inside <BODY>, inside <HEAD>, or as an external file. An external .js file can be reused across multiple pages, keeps HTML and JavaScript easier to read and maintain, and can speed up page loading.