CLASS 8 INTRODUCTION TO JAVASCRIPT
INTRODUCTION TO JAVASCRIPT
A. Tick the correct option
Which dialogue box prompts the user to enter value?
Answer: d. Prompt box
Which of the following is the extension for an external JavaScript file?
Answer: c. .js
Which of the following statement is not true about JavaScript?
Answer: a. It is not a case-sensitive language. (JavaScript is case-sensitive)
What is the other name for an object in JavaScript?
Answer: b. Key
Which of the following is not true about variable name?
Answer: a. It can contain space. (Variable names cannot contain spaces)
B. Fill in the blanks
Alert box displays a short message in a separate window.
Variable is the memory location that stores values.
document.writeln() object method displays the output with a line break.
The src attribute is used with external JavaScript.
The values of constants remain fixed.
C. State True or False
JavaScript cannot be used with HTML tags. — False
Looping means to repeat the statements multiple times till the condition is true. — True
By default, a variable in JavaScript is declared as global. — True
<script>tag cannot be placed inside the<head>tag. — FalseJavaScript is not an object-oriented language. — False(It is an object-based / prototype-based object-oriented language)
<SCRIPT> a. Used to embed JavaScript in HTML.E. Answer the following questions
1. Define JavaScript.
Answer: JavaScript is a dynamic, lightweight, client-side scripting language used to make web pages interactive and dynamic.
2. What is the usage of <SCRIPT> tag?
Answer: The <SCRIPT> tag (or <script>) is used in HTML documents to embed or reference executable JavaScript code.
3. Define a variable.
Answer: A variable is a named container or memory location used to store data values that can be referenced and modified during program execution.
4. Write another name for object in JavaScript.
Answer: An object in JavaScript is often referred to as a property container or a collection of key-value pairs (or an instance of a class/type).
5. Name two ways to embed JavaScript in HTML.
Answer:
Internal JavaScript: Writing script code directly inside the
<script>tag within the HTML file.External JavaScript: Linking an external file containing JavaScript code using the
srcattribute of the<script>tag (e.g.,<script src="script.js"></script>).
6. Write the features of JavaScript language.
Answer:
Lightweight and Interpreted: Executed directly by the browser without needing pre-compilation.
Client-Side Processing: Runs on the user’s browser, reducing server load.
Dynamic Typing: Variables do not require strict type definitions.
Event-Driven: Can react to user actions like button clicks, mouse hovers, and key presses.
Platform Independent: Works across all major operating systems and modern web browsers.
7. What is the difference between document.write() and document.writeln()?
Answer:
document.write(): Outputs text directly to the HTML document on the same line.document.writeln(): Outputs text to the HTML document and appends a new line character (\n) at the end of the content.
8. Write a few points one should keep in mind while naming a variable.
Answer:
Case Sensitivity: Variable names are case-sensitive (
myVarandmyvarare different).Allowed Characters: Names can contain letters, digits, underscores (
_), and dollar signs ($).First Character: A variable name must start with a letter, an underscore (
_), or a dollar sign ($), but cannot start with a number.Reserved Words: Reserved keywords (like
var,let,function,if) cannot be used as variable names.
9. Write the difference between confirm box and prompt box.
Answer:
confirm()Box: Displays a dialog box with a specified message along with OK and Cancel buttons. It returnstrueif OK is clicked andfalseif Cancel is clicked.prompt()Box: Displays a dialog box with a text input field along with OK and Cancel buttons. It allows the user to enter input and returns the entered text (ornullif canceled).
10. Explain the external JavaScript with an example.
Answer:
External JavaScript involves writing JavaScript code in a separate file saved with a .js extension, and then linking it to an HTML document using the src attribute inside the <script> tag. This improves code reusability and clean structure.
PROGRAM 01
PROGRAM 02
Comments
Post a Comment