JavaScript is a versatile, powerful scripting language used widely in web development. This chapter introduces JavaScript’s origins, setup steps, and foundational code practices to get you started coding directly in HTML.
Chapter 1: Introduction to JavaScript
Topic 1: History and Evolution of JavaScript
Which company developed JavaScript in 1995?
a) Microsoft
b) Netscape
c) Apple
d) Google
JavaScript was initially known as:
a) Mocha
b) Java
c) TypeScript
d) ECMAScript
What was the main purpose of creating JavaScript initially?
a) Building server applications
b) Adding interactivity to web pages
c) Managing databases
d) Machine learning
Who is considered the creator of JavaScript?
a) Tim Berners-Lee
b) Brendan Eich
c) Dennis Ritchie
d) Larry Page
In which year was ECMAScript 6, a major JavaScript update, released?
a) 2009
b) 2011
c) 2015
d) 2018
Which organization is responsible for the standardization of JavaScript?
a) ISO
b) ECMA
c) IEEE
d) W3C
Topic 2: Setting Up the Environment (Editors, Browsers)
Which of the following is NOT a commonly used code editor for JavaScript?
a) Visual Studio Code
b) Eclipse
c) MS Word
d) Atom
Which browser is NOT recommended for testing JavaScript?
a) Chrome
b) Firefox
c) Safari
d) Internet Explorer 6
To run JavaScript code, you need:
a) A text editor and a web browser
b) Only a text editor
c) Only a compiler
d) Special hardware
Which of the following tools is mainly used to debug JavaScript in modern browsers?
a) Developer Console
b) FTP
c) Task Manager
d) Windows PowerShell
Node.js is primarily used for:
a) Front-end development
b) Back-end development
c) Design work
d) File management
Which of these environments supports JavaScript?
a) Web browsers
b) Operating systems
c) Mobile phones only
d) Only on web servers
Topic 3: Writing and Running Your First JavaScript Code
JavaScript code can be written inside a file with which extension?
a) .java
b) .js
c) .jsx
d) .css
To display an alert box with a message, which command is used?
a) display(“Hello World”)
b) alert(“Hello World”)
c) console.log(“Hello World”)
d) popup(“Hello World”)
Which of these is correct syntax to print “Hello, World!” in the console?
a) print(“Hello, World!”)
b) alert(“Hello, World!”)
c) console.log(“Hello, World!”)
d) show(“Hello, World!”)
In which HTML tag can you write JavaScript code?
a) <html>
b) <body>
c) <script>
d) <link>
Which of the following is a valid way to add comments in JavaScript?
a) ## This is a comment
b) // This is a comment
c) <!-- This is a comment -->
d) * This is a comment
To create a variable in JavaScript, you can use which keyword?
a) int
b) let
c) define
d) const
Topic 4: JavaScript in HTML: <script> Tag and Inline Script
The <script> tag is typically placed in:
a) <header>
b) <footer>
c) <head> or <body>
d) <title>
An inline JavaScript code is written:
a) In an external .js file
b) Inside the HTML page directly
c) In a CSS file
d) In the server code
How do you link an external JavaScript file in HTML?
a) <script src="file.js">
b) <link src="file.js">
c) <style src="file.js">
d) <js src="file.js">
Which attribute must be included in the <script> tag for external files?
a) href
b) src
c) style
d) link
Inline scripts are written:
a) In the <script> tag with no src attribute
b) In the <script> tag with src attribute
c) In an external JavaScript file
d) None of the above
What attribute allows JavaScript to load asynchronously in HTML?
a) sync
b) async
c) defer
d) load
What is the purpose of the defer attribute in the <script> tag?
a) Loads script at the beginning of the page
b) Loads script before HTML parsing
c) Defers script loading until HTML is parsed
d) Prevents script from loading
Which code correctly embeds JavaScript directly into HTML?
a) <style>JavaScript code</style>
b) <script>JavaScript code</script>
c) <html>JavaScript code</html>
d) <code>JavaScript code</code>
An advantage of using external JavaScript files is:
a) Faster execution
b) Better security
c) Cleaner code structure
d) Higher browser compatibility
The <script> tag’s type attribute is often set to:
a) “text/css”
b) “application/xml”
c) “text/javascript”
d) “application/json”
What will the following code output in the browser console: console.log(5 + "5");?
a) 10
b) 55
c) Error
d) Undefined
Which of the following is NOT a correct way to include JavaScript in HTML?