Fundamentals of Web Programming
Fundamentals of Web Programming
Many people think WWW (World Wide Web) and Internet are the same, but they are different. Let’s
break it down in a simple way!
The Internet is like a huge network of computers all over the world, connected to share
information.
It is the physical infrastructure – cables, satellites, routers, and servers – that connect devices
like computers, phones, and tablets.
The Internet allows you to send emails, play online games, use social media, and browse websites.
Think of the Internet as the roads and highways that connect different cities!
Think of the WWW as the cars, houses, and buildings on the roads of the Internet!
Function Connects computers & devices Stores and displays web content
Includes Email, social media, online gaming, file sharing Websites, web pages, hyperlinks
1
Conclusion
The Internet is the big network, and the WWW is just one part of it (like a service that runs on
the Internet).
You can use the Internet without the WWW (e.g., sending an email or using WhatsApp).
But you need the Internet to access the WWW.
So next time someone says "I’m on the Internet," you’ll know if they mean using the web or
something else!
The internet allows people to communicate in different ways. Whether you want to chat with friends,
send emails, or share information, there are many options. Let’s explore them in detail.
What is it?
Email is like a digital letter. You can send messages, documents, and pictures to others.
Best for:
What is it?
Instant messaging allows real-time text communication.
Examples:
• Messenger
• Telegram
• Signal
2
• Add contacts.
Best for:
What is it?
Social media platforms help people connect, share updates, and interact.
• Create an account.
Best for:
What is it?
Video calling allows face-to-face communication over the internet.
• Use a microphone and camera for talking and seeing each other.
Best for:
What is it?
Online forums allow people to discuss topics and ask questions.
3
Examples:
• Quora
• Stack Overflow
Best for:
What is it?
People can share information, ideas, or experiences through blogs.
Best for:
What is it?
Gamers use chats to communicate while playing games.
Best for:
4
8. Online Customer Support (Live Chat, Chatbots)
What is it?
Many companies offer online support through live chat or chatbots.
Best for:
This is how you can communicate on the internet in different ways! Which one do you use the most?
The Domain Name System (DNS) is like the phonebook of the internet. It helps translate human-
friendly website names (like www.google.com) into numerical IP addresses (like 1️42️.2️50.1️82️.4) that
computers use to identify each other on the internet.
Computers communicate using IP addresses, which are long strings of numbers. However,
remembering numbers like 1️92️.1️68.1️.1️ for every website would be very difficult for humans. DNS
makes it easy by allowing us to use names instead.
For example:
Instead of typing 1️42️.2️50.1️82️.4, you can simply type www.google.com, and DNS will handle the
rest!
5
Whenever you type a website address (like www.facebook.com) in your browser, the following steps
happen:
• Your web browser sends a request to the DNS resolver (a special server) to find the IP address
of www.facebook.com.
• Your computer first checks if it already knows the IP address from a recent visit (stored in the
cache).
• The resolver first asks a Root DNS Server (the top-most level of DNS).
• The Root Server does not give the exact IP address but tells where to look next (TLD server).
• The TLD server handles domains like .com, .net, .org, etc.
• Since we are looking for facebook.com, the TLD server for .com is contacted.
• Now, your browser can connect to www.facebook.com using its IP address and load the
webpage!
6
1⃣ Recursive DNS Resolver – Finds the IP address by asking other DNS servers.
2⃣ Root DNS Server – Directs queries to the correct TLD server.
3⃣ TLD (Top-Level Domain) Server – Handles domain extensions like .com, .org, .net.
4⃣ Authoritative DNS Server – The final server that provides the actual IP address.
To make websites load faster, DNS responses are stored in cache (temporary memory).
This means, if you visit www.google.com today, and visit again tomorrow, your browser won’t need to
ask DNS servers again—it will remember the IP address.
Instead of using your ISP’s DNS, you can use faster, more secure DNS servers:
7
Google Public DNS → 8.8.8.8 & 8.8.4.4
Cloudflare DNS → 1️.1️.1️.1️ (Fast & Privacy-focused)
OpenDNS → 2️08.67.2️2️2️.2️2️2️
Conclusion
DNS is the backbone of the internet, making it easy for humans to browse websites without
remembering long IP addresses.
It works like a phonebook, translating domain names into IP addresses.
There are multiple layers of DNS servers, working together to provide the correct website
address.
Caching helps speed up DNS lookups, making websites load faster.
If DNS fails, websites won’t load, so changing to a reliable DNS provider can improve
performance.
The internet is a vast network that connects computers and devices worldwide. To access the
internet, you need to follow a few simple steps. Here’s a detailed and easy-to-understand
explanation:
An ISP (Internet Service Provider) is a company that provides internet access. Some common ISPs
include Airtel, Jio, BSNL, Comcast, and AT&T. You need to select a suitable plan based on speed, data
limit, and cost.
1. Modem – A device that connects your home to the ISP through a wired or wireless connection.
2. Router (Optional) – If you want Wi-Fi (wireless internet) for multiple devices, a router is
required. It distributes the internet connection.
3. Computer, Smartphone, or Tablet – The device you will use to access the internet.
o Connect the modem to the ISP’s cable using a telephone line, fiber optic cable, or
coaxial cable.
2. If using Wi-Fi, go to Wi-Fi settings, find your network name (SSID), and enter the password.
4. Sometimes, ISPs require login credentials or custom settings, which they provide.
3. If there is a problem, restart the modem and router or contact your ISP for troubleshooting.
• Mobile Data (4G/5G): Use a SIM card with a mobile internet plan. Enable mobile data in phone
settings.
• Public Wi-Fi: Connect to free Wi-Fi networks available in cafes, airports, and libraries.
By following these steps, you can easily connect to the internet and start browsing, streaming, and
communicating online!
Note on IP Addressing
What is an IP Address?
An IP Address (Internet Protocol Address) is a unique numerical label assigned to each device
connected to a network. It acts like a home address for devices on the internet or a local network,
allowing them to send and receive data correctly.
Types of IP Addresses
o Due to the rapid growth of the internet, IPv4 addresses are running out.
9
o Written in eight groups of four hexadecimal numbers (e.g.,
2001:0db8:85a3:0000:0000:8a2e:0370:7334).
Types of IP Addressing
1. Public IP Address
o Example: Websites, servers, and home routers use public IPs to connect globally.
2. Private IP Address
3. Static IP Address
4. Dynamic IP Address
• Subnetting helps divide a large network into smaller parts for better management and
security.
10
• CIDR (Classless Inter-Domain Routing) replaces the old class-based system and allows
efficient use of IP addresses. Example: 1️92️.1️68.1️.0/2️4, where /24 means the first 24 bits are
the network part.
Conclusion
IP addressing is essential for communication over networks and the internet. IPv4 is widely used, but
IPv6 is the future due to its larger address space. Understanding public/private, static/dynamic IPs,
and subnetting helps in better network management.
IP (Internet Protocol) addresses are unique identifiers assigned to devices on a network. They help in
communication between computers, servers, and other devices over the internet or a local network.
IP addresses are divided into five classes: A, B, C, D, and E. These classes define the range and
purpose of IP addresses.
1️. Class A
• Purpose: Used for large networks (like big organizations or internet service providers).
• Structure:
o Remaining three octets represent the host ID (individual devices in the network).
• Example: 10.0.0.1
Class A is suitable for large-scale networking because it can support up to 16 million devices!
2️. Class B
• Structure:
• Example: 172.16.0.1
3. Class C
11
• Purpose: Used for small networks (like homes, small businesses).
• Structure:
• Example: 192.168.1.1
Class C networks are common for home and office networks since they can support 254 devices.
4. Class D (Multicast)
• Purpose: Used for multicasting (sending data to multiple devices at the same time).
Class D is not used for normal device communication; it's used for broadcasting information to
groups of devices.
5. Class E (Experimental)
Class E is not used for regular networking. It is kept for future technologies.
Hope this explanation helps! Let me know if you need further clarification.
12
A Note on TCP/IP
What is TCP/IP?
TCP/IP stands for Transmission Control Protocol/Internet Protocol. It is the set of rules (protocols)
that allow computers to communicate over the internet and other networks. It defines how data is
sent, transmitted, received, and understood across different devices.
TCP/IP is the foundation of the internet. Without it, computers, smartphones, and other devices
wouldn’t be able to exchange information properly. It ensures that data sent from one device reaches
the correct destination safely and accurately.
Components of TCP/IP
o Responsible for breaking data into small packets before sending it.
o Ensures all packets are delivered correctly and in the right order.
o Provides error checking to detect lost or damaged packets and requests retransmission
if needed.
o Example: When you send an email or browse a website, TCP makes sure all parts of the
webpage or email arrive correctly.
2. IP (Internet Protocol)
o Every device connected to the internet has an IP address (like a home address) that
helps in identifying the sender and receiver.
o Example: When you visit a website, IP ensures that the data from the web server
reaches your computer.
1. Application Layer
o Includes web browsers (HTTP), email (SMTP), and file transfer (FTP).
2. Transport Layer
13
o Uses TCP (for reliable transmission) and UDP (for faster but less reliable transmission).
3. Internet Layer
o Uses protocols like IP, ICMP (for error reporting), and ARP (for address resolution).
o Deals with hardware and physical connections like cables, Wi-Fi, and Ethernet.
1. You open a web browser and type a website address (e.g., www.google.com).
2. The browser requests the website using HTTP (an application layer protocol).
3. The request is broken into small packets by TCP and sent over the network.
5. The packets travel through the internet and reach Google’s server.
6. Google’s server sends back the webpage data using the same TCP/IP process.
7. Your browser receives the packets, reassembles them, and displays the webpage.
Advantages of TCP/IP
Disadvantages of TCP/IP
Conclusion
TCP/IP is the backbone of the internet. It allows different devices to communicate by ensuring data is
transmitted accurately and efficiently. Whether browsing a website, sending an email, or streaming a
video, TCP/IP makes everything possible.
14
Aspect Website Webpage
www.example.com/contact (a specific
Examples www.example.com (a full website).
webpage).
The Domain Name System (DNS) is an essential part of how the internet functions. It acts like a phone
book for the internet, translating user-friendly domain names (like www.example.com) into IP
addresses (like 192.0.2.1) that computers use to identify each other on the network. Here’s a detailed
explanation in simple language:
What is DNS?
1. Purpose of DNS:
o When you want to visit a website, you typically enter a domain name in your web
browser. However, computers communicate using numerical IP addresses. DNS
translates the domain name into an IP address so that your computer can find and
connect to the server hosting that website.
2. Structure of DNS:
o DNS Records: DNS uses various types of records to store information about a domain.
Common types include:
15
▪ MX Record: Specifies the mail server responsible for receiving email on behalf of
a domain.
1. User Request:
o When you type a URL (like www.example.com) into your browser and hit enter, your
computer checks its local DNS cache to see if it already knows the IP address for that
domain.
o If the IP address is not in the cache, your request goes to a DNS resolver (usually
provided by your internet service provider). The resolver's job is to find the IP address for
the domain.
3. Root Nameservers:
o The resolver starts by querying a root nameserver. Root nameservers know where to find
the nameservers for top-level domains (like .com, .org, etc.).
4. TLD Nameservers:
o The root nameserver responds with the address of the TLD nameserver for .com. The
resolver then queries this TLD nameserver.
5. Authoritative Nameservers:
o The TLD nameserver responds with the address of the authoritative nameserver for the
specific domain (example.com). This authoritative nameserver holds the DNS records
for that domain.
o The resolver queries the authoritative nameserver, which responds with the IP address
of the domain (e.g., 192.0.2.1).
o Finally, the resolver sends this IP address back to your computer. Your browser can now
connect to the server at that IP address, allowing you to view the website.
Example
Let’s say you want to visit www.example.com. Here’s how DNS works step-by-step:
2. Your computer checks if it knows the IP address. If not, it asks the DNS resolver.
3. The resolver queries a root nameserver and gets the address of the .com TLD nameserver.
4. The resolver then asks the .com TLD nameserver, which provides the address of the
authoritative nameserver for example.com.
5. The resolver queries the authoritative nameserver and receives the IP address (e.g., 192.0.2.1).
16
6. The resolver returns the IP address to your computer.
7. Your browser connects to the web server at 192.0.2.1 and loads the website.
Conclusion
In summary, the Domain Name System (DNS) is a crucial part of the internet that makes it easy for
users to access websites using simple domain names instead of complicated numerical IP
addresses. It involves a series of queries through various types of nameservers to find the correct IP
address, allowing users to connect to the desired website seamlessly.
Domain names are an essential part of how we navigate the internet, and they are created based on
specific rules and procedures established by the Domain Name System (DNS). Here’s a detailed
explanation of how domain names are formed within the framework of DNS, using simple language:
o Domain names are structured in a hierarchical format and consist of several parts:
▪ Top-Level Domain (TLD): This is the last part of the domain name, such as .com,
.org, .net, or country-specific extensions like .uk, .ca, etc. TLDs indicate the
nature or location of the website.
▪ Subdomain: This is an optional part that precedes the second-level domain. For
example, in www.example.com, "www" is a subdomain often used to designate
the web version of the site.
o To create a domain name, you must register it with a domain registrar. Registrars are
organizations accredited by the Internet Corporation for Assigned Names and Numbers
(ICANN) or national authorities. They manage the reservation of domain names.
2. Availability Check:
o Before registering a domain name, you need to check if it is available. Each domain
name is unique, and if someone else has already registered it, you will need to choose a
different name.
17
3. Character Limitations:
▪ They can only include letters (a-z), numbers (0-9), and hyphens (-).
▪ The length of a domain name can range from 1 to 63 characters (not including
the TLD).
o Domain names are organized in a hierarchy. The highest level is the root, followed by
TLDs, second-level domains, and any subdomains. This structure helps in managing
and locating websites efficiently.
5. Naming Conventions:
o While creating a domain name, it’s important to choose a name that is easy to
remember, spell, and pronounce. Many businesses choose names that reflect their
brand or the services they provide.
Let’s say you want to create a website for a bakery named "Sweet Treats." Here’s how you would form
a domain name for it:
1. Choose a Domain Name: You might consider sweettreats.com as your domain name.
2. Check Availability: You would check with a domain registrar to see if sweettreats.com is
available. If it is taken, you may need to consider variations like sweettreatsbakery.com or
sweettreats.net.
3. Register the Domain: Once you find an available name, you would register it through a domain
registrar, which involves providing your information and paying a registration fee.
4. Follow Naming Rules: Ensure your chosen name follows the character limitations and
conventions mentioned earlier.
Conclusion
In summary, domain names are formed according to the rules and procedures established by the
Domain Name System (DNS). This includes registering the name through a registrar, ensuring its
availability, adhering to character limitations, and following naming conventions. By understanding
these processes, individuals and organizations can create memorable and functional domain names
that help them establish their presence on the internet.
Here are the rewritten questions along with their answers and explanations:
18
1. A ........................... is a software application which enables a user to display and interact
with text, images, videos, music, and other information that could be on a website.
Answer: A. Browser
Meaning: A browser is a software application that allows users to access and navigate the
web, displaying various types of content including text, images, and multimedia.
2. A ........................... is what you see on the screen when you type in a web address, click
on a link, or put a query in a search engine.
Answer: B. Web Page
Meaning: A web page is a document on the World Wide Web that can be displayed in a
browser, containing text, images, and links to other pages.
6. ........................... splits the signal in the telephone wire in two: voice and broadband.
Answer: B. Micro Filter
Meaning: A micro filter is a device used in telecommunications to separate voice signals from
broadband data signals on a telephone line.
7. The ........................... tab allows you to access the set of "Available" networks.
Answer: B. Wireless Networks
Meaning: The Wireless Networks tab in a network management interface displays a list of Wi-
Fi networks available for connection.
9. Using the ........................... function we get a list of all the IP addresses the hostname
resolves to.
Answer: A. System.Net.Dns.Get Host Entry
19
Meaning: The System.Net.Dns.GetHostEntry function retrieves the IP address associated with
a specified hostname, providing a way to resolve domain names to IP addresses.
10. A ........................... is the standard hostname given to the address assigned to the
loopback network interface.
Answer: B. Local Host
Meaning: "Local Host" refers to the standard hostname for the loopback interface, typically
used to establish a network connection to the same machine.
11. Communication technologies are unique to networked computer environments and have
come into wide popularity because of the Internet.
Answer: A. True
Meaning: This statement is true as communication technologies, such as email and instant
messaging, have become prevalent due to the Internet and its ability to connect devices and
users globally.
14. TCP handles ........................... between systems and IP handles the routing of packets.
Answer: Packet Flow
Meaning: TCP (Transmission Control Protocol) manages the transmission of data packets
between systems, ensuring reliable and orderly communication, while IP (Internet Protocol) is
responsible for directing those packets to their destinations.
15. The ........................... protocol with seven layers is the usual reference model.
Answer: ISO/OSI
Meaning: The ISO/OSI (International Organization for Standardization/Open Systems
Interconnection) model is a conceptual framework that standardizes the functions of a
telecommunication or computing system into seven layers.
HTML, or Hypertext Markup Language, was created by Tim Berners-Lee in 1991 while he was working
at CERN (the European Organization for Nuclear Research). The goal was to facilitate document
sharing over the internet.
20
• HTML 1️.0: The first version of HTML, released in 1993, allowed for basic document structure,
including headings, paragraphs, links, and images.
• HTML 2️.0: Released in 1995, it included more elements and features, like forms and tables.
• HTML 3.2️: Introduced in 1997, this version added support for applets, tables, and improved
styling.
• HTML 4.01️: Released in 1999, it brought improvements for multimedia support, scripting, and
accessibility.
• XHTML: In the early 2000s, a stricter version of HTML was developed, combining HTML and
XML (extensible Markup Language).
• HTML5: Released in 2014, it introduced new elements and APIs (Application Programming
Interfaces) for multimedia, better support for web applications, and improved semantics.
HTML5 is the current standard.
HTML continues to evolve, with ongoing updates to improve functionality and usability.
HTML provides several tags for formatting and manipulating text. Some commonly used tags include:
• <h1> to <h6>: These are heading tags, with <h1> being the largest and <h6> the smallest.
• <strong>: This tag is used to make text bold and indicate strong importance.
• <hr>: This tag inserts a horizontal rule, typically used to separate sections.
• <blockquote>: This tag is used for quotations, typically displayed with indentation.
• <span>: A generic inline container that can be used to apply styles or scripts to a portion of
text.
Advantages:
• Simplicity: HTML is relatively easy to learn and use, making it accessible to beginners.
• Wide Compatibility: HTML is supported by all web browsers, ensuring that web pages can be
viewed across different platforms.
• Structured Documents: HTML helps create a structured document, improving readability and
SEO (Search Engine Optimization).
• Multimedia Integration: HTML supports embedding images, audio, and video, enhancing web
content.
Limitations:
21
• Static Nature: HTML alone is static and cannot create dynamic content. To create dynamic
websites, additional technologies like JavaScript are needed.
• Limited Design Control: HTML provides basic styling capabilities, but for advanced design,
CSS (Cascading Style Sheets) is required.
• Not Suitable for Complex Applications: HTML is not designed for complex applications.
Server-side scripting languages like PHP or frameworks are needed for advanced
functionalities.
• Singular Tags: These tags do not require a closing tag. They are self-contained and perform
their function without needing to enclose other content. Examples include:
• Paired Tags: These tags consist of an opening tag and a closing tag, with content in between.
The closing tag is marked with a forward slash (/). Examples include:
o <p>Content goes here</p>: The opening <p> tag starts a paragraph, and the closing
</p> tag ends it.
1. Choose a Web Server Software: Popular options include Apache, Nginx, and Microsoft IIS.
These programs run on the server and handle requests from users' browsers.
2. Install the Server: Depending on the software you choose; you’ll need to install it on your
server. This often involves downloading the software and following installation instructions.
3. Configure the Server: Set up the server to meet your needs. This can include:
o Defining the root directory where your website files will be stored.
4. Upload Your Files: Place your HTML, CSS, and other files in the server's root directory. This can
be done via FTP (File Transfer Protocol) or directly through the server’s file manager.
5. Start the Server: Once configured, start the server software. It will listen for incoming requests
from web browsers.
22
6. Access the Website: You can access your website by entering your server's IP address or
domain name into a web browser. The server will respond by sending the requested files (like
your HTML pages) back to the browser.
7. Maintenance and Monitoring: Regularly update your server software, back up files, and
monitor performance to ensure everything runs smoothly.
By understanding these concepts, you can better grasp how HTML functions within the broader
context of web development!
Here are detailed explanations for your questions regarding HTML and related concepts, formatted
with creative symbols and headings for clarity.
6. Advantages of HTML
HTML (HyperText Markup Language) is the standard language for creating web pages. Here are some
advantages:
Simplicity:
HTML is easy to learn and use. Its syntax is straightforward, making it accessible for beginners.
Platform Independence:
HTML documents can be viewed on various devices (like computers, tablets, and smartphones)
without needing special software.
SEO Friendly:
Search engines can easily read and index HTML content, helping websites rank higher in search
results.
Hyperlinking:
HTML allows for the creation of hyperlinks, enabling easy navigation between web pages and
websites.
A web browser is a software application that enables users to access and view content on the World
Wide Web. Here are some key points:
Functionality:
Browsers retrieve, present, and traverse information on the internet. They interpret HTML, CSS, and
JavaScript to display web pages.
Popular Examples:
Some common web browsers include Google Chrome, Mozilla Firefox, Microsoft Edge, and Safari.
User Interface:
Browsers provide an interface that includes a navigation bar, bookmarks, tabs, and various tools for
browsing and searching.
23
Security Features:
Modern browsers include features to protect users from malware, phishing, and insecure websites.
• XML (eXtensible Markup Language): Used for data storage and transport.
Purpose:
Markup languages help browsers understand how to display content, allowing for structured,
organized documents.
Here’s a detailed explanation of the differences between DHTML and XHTML, presented in a simple
and creative format:
Definition:
DHTML stands for Dynamic Hypertext Markup Language. It is not a specific language but a
combination of HTML, CSS, and JavaScript that allows web pages to be more interactive and dynamic.
• Interactivity:
o Makes web pages dynamic by allowing content to change without reloading the
page.
o Users can interact with elements (e.g., clicking buttons, hovering over items) to
trigger changes.
• CSS Manipulation:
o Allows real-time styling changes using CSS. For example, changing colors, fonts, or
layouts based on user actions.
• JavaScript Functionality:
24
o Uses JavaScript to manipulate the Document Object Model (DOM), enabling
dynamic updates and animations.
• User Experience:
Definition:
XHTML stands for Extensible Hypertext Markup Language. It is a stricter and more standardized
version of HTML that follows XML syntax rules.
• Well-formed Structure:
o Requires all elements to be properly nested and closed. For example, <br> must be
written as <br />.
• Case Sensitivity:
o All tags and attributes in XHTML must be in lowercase, unlike HTML where case
sensitivity is not enforced.
o Being XML-based, XHTML documents can be parsed and processed by XML tools,
allowing for better integration with other technologies.
Syntax Rules Follows HTML rules Follows strict XML syntax rules
25
Feature DHTML XHTML
Summary
• DHTML is all about making web pages dynamic and interactive using HTML, CSS, and
JavaScript, enhancing the user experience.
• XHTML, on the other hand, focuses on maintaining a strict syntax and structure, ensuring that
web documents are well-formed and compatible with XML.
By understanding these differences, you can choose the right approach for your web development
needs, ensuring both functionality and structure in your web projects!
HTML, or HyperText Markup Language, is the standard language used to create web pages. Let’s
explore how HTML came to be, its evolution, and its basic structure in simple terms.
What is HTML?
HTML is a markup language that defines the structure of web pages. It uses "tags" to describe the
elements on a page, such as headings, paragraphs, links, images, and more.
• Tim Berners-Lee: A British computer scientist, Tim Berners-Lee, proposed a system for
sharing information across the Internet.
• First Draft: In 1991, he released the first draft of HTML, which contained 18 tags that allowed
basic text formatting and linking.
• Standardization: The Internet Engineering Task Force (IETF) created HTML 2.0 as the first
formal specification of HTML.
• Basic Features: It included essential features like forms, tables, and images.
26
• Wider Adoption: As the web grew, the World Wide Web Consortium (W3C) took over the
development of HTML.
• New Tags: HTML 3.2 introduced new elements like tables and applets, enhancing the
capabilities of web pages.
• Improvement and Accessibility: This version focused on improving the language for
accessibility and internationalization.
• Separation of Content and Presentation: It encouraged the use of CSS (Cascading Style
Sheets) for styling.
• XML Syntax: XHTML was developed to enforce stricter syntax rules based on XML, allowing for
better data interchange.
• Legacy Support: While it was an evolution, many developers continued to use HTML 4.01.
6. HTML5: 2️01️4
• Major Upgrade: HTML5 introduced new features such as multimedia support (audio and
video), new semantic elements (like <header>, <footer>, and <article>), and APIs for improved
web applications.
• Responsive Design: It made it easier to create web pages that work well on various devices,
from desktops to smartphones.
An HTML document consists of several key parts, structured in a specific way. Here’s a simple
breakdown:
</head>
</body>
</html>
27
Key Elements Explained:
• <!DOCTYPE html>: This tells the browser that this document is an HTML5 document.
• <title>: Sets the title of the page that appears in the browser tab.
Conclusion
HTML has evolved significantly since its inception, becoming the backbone of web development.
Understanding its structure and history is essential for anyone interested in creating websites or web
applications. As the web continues to grow, HTML will keep adapting to meet new challenges and
technologies!
1. ........................... is a markup language which tells the web browser how to display
content.
Answer: C. HTML
Meaning: HTML (Hypertext Markup Language) is the standard markup language used to create
web pages. It provides the structure and layout for web content.
2. A ....................... is a language that annotates text so that the computer can manipulate
the text.
Answer: B. Markup Language
Meaning: A markup language is designed for the processing, definition, and presentation of
text. It uses annotations to define the structure and formatting of the text.
28
5. .......................... is used in voice interaction between humans and computers.
Answer: B. VoiceXML
Meaning: VoiceXML is a markup language designed for creating interactive voice response
applications, allowing voice-based communication with computers.
6. A ........................... is a program that, using the client/server model and the World Wide
Web’s Hypertext Transfer Protocol (HTTP), serves the files that form Web pages to Web
users.
Answer: A. Web Server
Meaning: A web server is software that delivers web pages to users' browsers via HTTP,
handling requests from clients and sending back the requested content.
7. Every computer on the Internet that contains a ........................... must have a Web server
program.
Answer: D. Web site
Meaning: Any computer hosting a website must have a web server to manage requests and
deliver content over the Internet.
11. ........................... present in resources enable users easily to navigate their browsers to
related resources.
Answer: Hyperlinks
Meaning: Hyperlinks are clickable links that connect different web pages or resources,
allowing users to easily navigate the web.
12. Many browsers offer ........................... which extend the capabilities of a browser so it
can display multimedia information.
Answer: Plug-ins
Meaning: Plug-ins are software components that add specific features or functionalities to a
web browser, enabling it to handle various multimedia formats.
13. ........................... are instructions that are embedded directly into the text of an HTML
document.
29
Answer: Tags
Meaning: Tags are the fundamental building blocks of HTML that define the structure and
elements of a web page.
14. In paired tags, the first tag is referred to as Opening Tag and the second tag is referred to
as ........................... Tag.
Answer: Closing
Meaning: The closing tag is used to indicate the end of an element in HTML, and it is typically
written with a forward slash (/) before the tag name.
15. A tag is said to be a ........................... tag if the text is placed between a tag and its
companion tag.
Answer: Paired
Meaning: A paired tag consists of an opening tag and a closing tag that enclose content,
defining the scope of the element.
HTML commands, often referred to as tags, are the building blocks of an HTML document. They are
used to create elements on a webpage. Each command typically consists of an opening tag and a
closing tag.
Example:
Usage:
HTML commands are used to structure content, such as headings, paragraphs, links, images, and
lists. They help the web browser understand how to display the content.
Advantages:
Limitations:
30
Static Nature: HTML alone is static, meaning it does not support dynamic content without
additional languages like JavaScript.
Limited Styling: Basic HTML provides limited styling options. For advanced designs, CSS is
needed.
Browser Compatibility: Older browsers may not fully support the latest HTML features.
No Programming Logic: HTML cannot perform calculations or data manipulations, as it is not a
programming language.
An HTML program has a standard structure that includes several essential components:
</head>
</body>
</html>
Breakdown:
• <body>: Contains the actual content of the webpage, such as text, images, and links.
• Bold: <strong>text</strong>
Example: <strong>This is bold text.</strong> results in This is bold text.
• Italic: <em>text</em>
Example: <em>This is italic text.</em> results in This is italic text.
31
• Underline: <u>text</u>
Example: <u>This text is underlined.</u> results in This text is underlined.
Text effects refer to the visual enhancements applied to text to improve its presentation and
emphasis. These effects can be achieved through CSS or HTML tags.
Text effects enhance readability and visual appeal, making web pages more engaging for users.
This overview covers the key concepts of HTML, including commands, structure, text formatting, and
effects, in a simple and organized manner. Let me know if you have any more questions!
Sure! Let's break down these topics one by one in a simple and detailed way, using headings and
creative symbols for clarity.
Header tags in HTML are used to define headings on a webpage. There are six levels of header tags,
ranging from <h1> to <h6>. Here’s what they look like:
• <h1️>: This is the highest level heading, typically used for the main title of a page.
• <h2️>: This tag represents the second level heading, used for main sections.
• <h3>: The third level heading, used for subsections under an <h2>.
32
o Example: <h3>Our Mission</h3>
• <h6>: This is the lowest level heading, often used for the least important sections.
Preformatted text in HTML is used to display text exactly as it is written in the HTML document,
including spaces and line breaks. This is done using the <pre> tag.
• Example:
• <pre>
• line breaks.
• </pre>
• Maintains whitespace and formatting, making it useful for code snippets or ASCII art.
Preformatted text is essential when you want to show text that requires a specific layout. The <pre>
tag tells the browser to display text in the exact format it is written.
• Use Cases:
o Code Samples: When showing programming code, it’s vital to maintain indentation and
formatting.
33
o Poems or Lyrics: Any text where formatting is crucial for understanding.
Example:
<pre>
function helloWorld() {
console.log("Hello, World!");
</pre>
This code will display exactly as written, maintaining indentation and line breaks.
• Maintain Formatting: Always remember that the <pre> tag preserves whitespace and line
breaks. Use it when you need this feature.
• Use Appropriate Font Size: The default font may not always be readable, so consider
adjusting font size and type for better visibility.
• Avoid Excessive Length: Avoid using <pre> for very long text blocks as it can lead to
horizontal scrolling, making it hard to read.
• Combine with Other Elements: You can use <pre> with other HTML elements to create
more complex layouts while maintaining the preformatted text.
HTML provides various tags for formatting text to enhance readability and structure. Here are some
commonly used formatting tags:
1. HTML ........................... tells a web browser where the HTML part in your document
begins and ends.
Answer: B. tags
Meaning: Tags in HTML are special codes that indicate the start and end of HTML elements,
allowing the web browser to understand how to render the content.
2. The “...........................” contains all of the document’s header information like the web
document’s title and information about the document itself.
Answer: D. head
Meaning: The <head> section of an HTML document includes metadata, title, links to
stylesheets, and scripts, which provide essential information about the document.
5. A ........................... tag describes how the text is being used, not necessarily how it is
formatted.
Answer: D. logical character
Meaning: Logical character tags indicate the meaning of the text (e.g., emphasis or strong
importance) rather than just its visual appearance.
6. The ........................... font style slants the text to the right and thus can also be used to
draw special attention to one or more words.
Answer: A. italics
Meaning: Italics are used in text formatting to create a slanted effect, often employed for
emphasis or to denote titles of works.
35
7. A HTML ........................... is basically separated into two parts: the head and the body.
Answer: D. Document
Meaning: An HTML document is structured into two main sections, the <head> and the
<body>, where the head contains metadata and the body contains the content displayed on
the web page.
8. Every well-written HTML document begins with a basic declaration that defines what type
of document it is, and this declaration is made using the ........................... tag.
Answer: C. !DOCTYPE
Meaning: The <!DOCTYPE> declaration is used to specify the HTML version being used,
helping browsers render the page correctly.
9. ........................... tag is used to create a horizontal line on your page you use the empty
tag.
Answer: A.
Meaning: The <hr> tag creates a horizontal rule (line) in HTML, often used to separate sections
of content visually.
11. Using ........................... is helpful in situations where you just need one or two spaces in
between characters or words for stylistic or aesthetic effect.
Answer:
Meaning: The (non-breaking space) entity creates a space in HTML where regular
whitespace is collapsed, allowing for precise spacing.
12. The tag ........................... changes the color of a few words or a section of text.
Answer: Font Color
Meaning: The <font> tag with the color attribute can be used to change the text color in HTML,
although it is now deprecated in favor of CSS.
13. The code to align text in HTML for a post or single page is ...........................
Answer:
Meaning: The <p align="direction"> attribute is used to specify the alignment of paragraph text
in HTML (e.g., left, right, center).
14. ........................... tag is a non-standard tag and can be very irritating if used on large areas
of text, so use it sparingly.
Answer:
Meaning: The <blink> tag was used to create blinking text but is considered non-standard and
can be distracting, so it's not recommended for use in modern web design.
15. ........................... tag is used to create a moving text effect, similar to some “matrix” type
LED and illuminated signs.
Answer:
36
Meaning: The <marquee> tag creates scrolling text effects in HTML, but it is also deprecated
and should be used with caution.
When preparing an order list, it's important to focus on specific information to ensure accuracy and
efficiency. Here are the key elements to emphasize:
• Item Description: Clearly state what each item is (e.g., product name, size, color).
• Supplier Information: Note the source of each item for easy reordering.
• Special Instructions: Include any specific details or requests for each item.
HTML offers several methods to create lists, primarily categorized into three types:
• Ordered Lists (ol): For lists where the order matters (e.g., steps in a recipe).
• Unordered Lists (ul): For lists where the order doesn't matter (e.g., shopping items).
• Description Lists (dl): For lists of terms and their descriptions (e.g., glossary terms).
Each type uses specific HTML tags to define the list and its items.
Let’s look at how to create ordered lists, unordered lists, and nested lists in HTML.
An ordered list is created using the <ol> tag, and each item is defined with the <li> tag.
<ol>
</ol>
<ul>
<li>Milk</li>
<li>Bread</li>
<li>Eggs</li>
</ul>
Nested Lists
You can create lists within lists (nested lists) by placing an ordered or unordered list inside a list item.
<ul>
<li>Fruits
<ul>
<li>Apple</li>
<li>Banana</li>
</ul>
</li>
<li>Vegetables
<ol>
<li>Carrot</li>
<li>Broccoli</li>
</ol>
</li>
</ul>
4. IMG Attributes
The <img> tag is used to embed images in HTML. Here are some important attributes:
• alt: Provides alternative text for the image, which is important for accessibility and displays if
the image fails to load.
• title: Adds a tooltip that appears when the user hovers over the image.
38
Example:
Aligning images in HTML can enhance the layout of your page. Here are some alignment methods:
• Align Attribute (Deprecated): Older versions of HTML used the align attribute. Although it's
deprecated in HTML5, it's good to know for legacy code.
<style>
.center {
display: block;
margin-left: auto;
margin-right: auto;
</style>
Using these methods helps you control the layout and position of images on your web page.
HTML provides three main types of lists, each serving different purposes:
• Use Case: Best for lists where the sequence of items doesn’t matter.
• Example:
• <ul>
• <li>Apples</li>
• <li>Bananas</li>
39
• <li>Cherries</li>
• </ul>
• Use Case: Ideal for lists where the order is important, like steps in a recipe.
• Example:
• <ol>
• </ol>
• Example:
• <dl>
• <dt>HTML</dt>
• <dt>CSS</dt>
• </dl>
40
• Adding Items: Use the <li> tag to add items within an <ul>.
• <ul>
• <li>Item 1</li>
• <li>Item 2</li>
• </ul>
• Nesting Lists: You can create a sub-list by adding another <ul> within an <li>.
• <ul>
• <li>Fruits
• <ul>
• <li>Apple</li>
• <li>Banana</li>
• </ul>
• </li>
• <li>Vegetables</li>
• </ul>
• ul {
• }
• Syntax:
• Attributes:
o alt: Provides alternative text for the image (important for accessibility).
• Example:
41
1️0. Classes of HTML List
• Description: These lists occupy the full width of the parent container.
• li {
• display: inline-block;
• }
3. Nested Lists
• Example:
• <ul>
• <li>Main Item
• <ul>
• </ul>
• </li>
• </ul>
1. The ........................... classes allow you to easily create lists within your HTML pages.
Answer: A. HTML List
Meaning: The HTML List classes, such as <ul> (unordered list) and <ol> (ordered list), enable
you to create various types of lists on your web pages.
2. The ........................... OrderedList and OrderedListItem are used to create ordered lists in
your HTML pages.
Answer: C. Classes
42
Meaning: Classes like OrderedList and OrderedListItem are used in some frameworks or
libraries to create ordered lists, enhancing organization and styling.
3. By using the methods in ..........................., you can override the numbering and type for a
specific item in the list.
Answer: D. OrderedListItem
Meaning: The OrderedListItem class provides methods to customize the appearance and
numbering of specific items in an ordered list.
4. ........................... lists are purely a list of related items, in which their order does not
matter nor do they have a numbered or alphabetical list element.
Answer: B. Unordered
Meaning: Unordered lists consist of items where the sequence is not important, typically
represented with bullet points.
6. The solid dot is referred to as the list item element and can be changed using
...........................
Answer: C. CSS
Meaning: CSS (Cascading Style Sheets) can be used to modify the appearance of list items,
including changing the bullet style.
9. The ........................... actually requires two elements: the definition term element, dt,
and the definition description element, dd.
Answer: B. Definition list
Meaning: A definition list requires both <dt> (definition term) and <dd> (definition description)
elements to properly format terms and their meanings.
43
Answer: <IMG>
Meaning: The <IMG> tag is used in HTML to embed images in a web page.
12. The only way to center a graphic horizontally on a page is to use <CENTER>&</CENTER>
tags around the ........................... tag.
Answer: <IMG SRC>
Meaning: The <CENTER> tags can be used to center an image in older HTML standards,
wrapping around the <IMG SRC> tag.
13. “...........................” aligns the bottom of the image with the bottom of the current line.
Answer: ABSBOTTOM
Meaning: The ABSBOTTOM value is used in the align attribute of the <IMG> tag to position the
bottom of the image with the baseline of surrounding text.
HTML tables are used to display data in a structured format with rows and columns. Tables help
organize information visually.
• Inside the table, you create rows with the <tr> tag.
• Each row contains data cells represented by <td> (table data) tags.
• You can also add header cells with the <th> (table header) tag.
<table>
<tr>
44
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
<tr>
<td>Data 3</td>
<td>Data 4</td>
</tr>
</table>
<table>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>Alice</td>
<td>30</td>
</tr>
<tr>
<td>Bob</td>
<td>25</td>
</tr>
</table>
3. Linking Documents
45
Linking documents in HTML means connecting one web page to another. This is primarily done using
hyperlinks, which allow users to navigate between different resources.
Creating a Hyperlink:
• The href attribute specifies the URL of the page you want to link to.
Example:
When a user clicks on this link, it will take them to the specified URL.
The <body> tag represents the content of the web page. Here are three important attributes you can
specify:
Definition of Hyperlinks: Hyperlinks, or links, are elements in a web page that allow users to click
and navigate to another page or resource. They are fundamental to web navigation.
Types of Hyperlinks:
• Internal Links: These link to another page within the same website.
• Anchor Links: These link to a specific section within the same page.
Conclusion: Hyperlinks enhance the user experience by allowing easy navigation and access to more
information.
46
6. Justify the Use of Link List Creation in an HTML Document
A link list is a collection of hyperlinks that allows users to navigate through a website or between
different websites.
• Improved Navigation: Link lists provide a clear structure for users to find related content
easily.
• Accessibility: They help visually impaired users using screen readers to understand the
layout and navigate effectively.
• SEO Benefits: Search engines use link lists to crawl and index pages, improving the site's
visibility.
• Organization: They help in categorizing related links (e.g., resources, references) making it
easier to manage content.
Example
<ul>
</ul>
Adding Borders
To display a table with borders, you can use the border attribute in the <table> tag or apply CSS styles.
Example
<table border="1">
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>Alice</td>
47
<td>30</td>
</tr>
<tr>
<td>Bob</td>
<td>25</td>
</tr>
</table>
<style>
table {
th, td {
</style>
To link to a page on another website, use the <a> (anchor) tag with the href attribute pointing to the
URL.
Example
Explanation
• When users click on this link, they will be directed to the specified website. Using
target="_blank" is useful for keeping users on your site while allowing them to explore other
sites.
48
9. Steps to Move to a Specific Location on a Web Page
To move to a specific location on a web page, you can use anchor links, which navigate to a specific
section of the page.
Steps
Example
Explanation
• Clicking the link will scroll the page to the part marked with id="section1". This is particularly
useful for long web pages with multiple sections.
2. The letters ........................... stands for “table data,” which is the content of a data cell.
Answer: A. TD
Meaning: The <td> tag (table data) is used to define individual cells within a table row,
containing the data displayed in the table.
3. A ........................... can contain text, images, lists, paragraphs, forms, horizontal rules,
tables, etc.
Answer: C. Data Block
Meaning: A data block refers to a section of content that can encompass various elements like
text, images, and more, typically represented in structured formats like tables.
49
Meaning: The <tr> tag (table row) is used to define a row in an HTML table, which can contain
one or more data cells.
5. When you finish all of the cells for a row, you would then close the row with the ending row
tag, ...........................
Answer: C. </tr>
Meaning: The </tr> tag is used to close a table row definition in HTML, indicating the end of that
row's content.
6. If you do not specify a ........................... attribute, the table will be displayed without any
borders.
Answer: A. Border
Meaning: The border attribute determines whether the table has visible borders. Without this
attribute, the table will not display any borders.
9. The text between the <a> and the </a> is used as the ........................... for the link.
Answer: C. Caption
Meaning: The text inside the <a> tags serves as the caption or clickable text of the link, which
users see and click on.
10. You can use a/an ........................... to separate words in your file names.
Answer: A. Underscore, “_”
Meaning: Using an underscore (_) is a common practice for separating words in file names,
enhancing readability.
11. If the file is not present in the current directory, a ........................... path can be specified.
Answer: Relative or Absolute
Meaning: A relative path refers to the location of a file in relation to the current directory, while
an absolute path specifies the full path from the root of the file system.
12. If you want to preserve all of your links and space of your blog you can use
........................... box which contains link list.
Answer: Scrollable
Meaning: A scrollable box is a user interface element that allows users to scroll through a list
of links, keeping the blog layout neat and organized.
13. The ........................... tag defines a division or a section in an HTML document. In a div
element, the overflow property is set to auto.
Answer: <div>
50
Meaning: The <div> tag is used to create a block-level division in an HTML document, often
used for styling and layout purposes.
15. Image ........................... are constructed by embedding an <img> tag inside of an anchor
element <a>.
Answer: Links
Meaning: Image links are created by wrapping an <img> tag within an <a> tag, allowing users to
click on the image to navigate to a different page or resource.
Chapter 6: DHTML
Here’s a differentiation between HTML and DHTML in tabular form:
Technologies
Uses HTML tags only. Combines HTML, CSS, and JavaScript.
Used
User Basic user experience; primarily Enhanced user experience; allows for
Experience displays content. interactive features and real-time updates.
Basic web pages with text and Web applications with interactive elements
Examples
images. like menus, forms, and animations.
HTML stands for HyperText Markup Language. It's the foundation of web pages. Think of it as the
skeleton of a webpage. With HTML, you create the structure and layout by using various tags (like <h1>
for headings, <p> for paragraphs, and <a> for links). However, HTML alone cannot create interactive or
dynamic content. It simply displays text and images as they are written.
What is DHTML?
DHTML, or Dynamic HTML, is a more advanced version of HTML. It combines HTML with Cascading
Style Sheets (CSS) and JavaScript to create interactive and animated web pages. DHTML allows
content to change without needing to reload the entire page. For instance, when you hover over a
button and it changes color or reveals a hidden menu, that’s DHTML in action.
o HTML: Once the page is loaded, nothing changes unless you refresh it.
o DHTML: The page can change in response to user actions without a full refresh.
• Interactivity:
o HTML: You can click links or fill out forms, but there’s little else happening.
o DHTML: You can have moving elements, dropdown menus, and other engaging
features.
• User Experience:
o DHTML: Makes the website lively and engaging, improving the overall experience.
Conclusion
In summary, HTML is essential for building the basic structure of web pages, while DHTML takes it a
step further by introducing interactivity and dynamic content. If you want to create modern, engaging
web experiences, learning DHTML (or the technologies it comprises) is the way to go!
• Interactivity: DHTML allows users to interact with web pages through animations and
dynamic changes, making the experience more engaging.
• Real-time Updates: Content can be updated in real-time without requiring a full page
reload, enhancing user experience.
• Styling Control: With CSS in DHTML, developers can apply styles dynamically, creating
visually appealing designs.
52
• Responsive Design: DHTML supports responsive layouts that adapt to different screen
sizes, improving accessibility on various devices.
• Separation of Concerns: Using an external style sheet (CSS file) separates content from
presentation, making the HTML cleaner and easier to manage.
• Consistency: You can apply the same styles across multiple pages, ensuring a uniform
look and feel throughout the website.
• Ease of Maintenance: Changing styles in one external file updates all linked pages, saving
time and effort in maintaining your website.
• Improved Loading Time: Browsers cache external style sheets, which can improve page
load times when navigating between different pages.
4. What is CSS?
• Definition: CSS (Cascading Style Sheets) is a stylesheet language used to describe the
presentation of a document written in HTML. It controls the layout, colors, fonts, and overall
visual appearance of web pages.
• Key Features:
o Selectors: CSS uses selectors to target HTML elements for styling (e.g., class, id, or
element types).
o Box Model: CSS manages spacing and positioning of elements using margins, borders,
padding, and content areas.
o Responsive Design: Media queries allow CSS to adapt layouts based on the device’s
screen size.
• Benefits:
5. What is Class?
• Definition: In HTML and CSS, a class is an attribute that can be added to an HTML element
to apply specific styles or behaviors. It allows multiple elements to share the same style.
• Usage:
o Classes are defined in the HTML element using the class attribute. For example: <div
class="myClass">Content</div>.
53
o In CSS, styles are applied to all elements with that class. For example:
o .myClass {
o color: blue;
o font-size: 20px;
o }
• Benefits:
o Reusability: You can define styles once and apply them to multiple elements, reducing
redundancy.
Definition:
An external style sheet is a separate CSS (Cascading Style Sheets) file that contains styles for
multiple web pages. This allows for a consistent design across a website.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Website</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
Dynamic HTML (DHTML) is an advanced version of HTML that allows for interactive and animated
web pages. Here are some of its key features:
54
• Dynamic Content:
o Content can change without reloading the entire page. This enhances user experience.
• Interactive Elements:
o Users can interact with elements like buttons, forms, and images, leading to a more
engaging experience.
• Animations:
o DHTML allows for animations and transitions, making the web pages visually appealing.
• Positioning:
• Event Handling:
o DHTML responds to user actions, such as clicks and key presses, to trigger events and
updates.
• JavaScript Manipulation:
o JavaScript can change the content and style of HTML elements dynamically. For
example, you can use JavaScript to change text or hide/show elements.
• Event Handling:
o JavaScript listens for user actions (like clicks) and executes code to manipulate the
page in real time.
o DHTML utilizes the DOM, which represents the structure of a web page. JavaScript can
interact with the DOM to change elements, styles, and attributes.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>DHTML Example</title>
<style>
#myDiv {
width: 100px;
55
height: 100px;
background-color: blue;
</style>
<script>
function changeColor() {
document.getElementById("myDiv").style.backgroundColor = "red";
</script>
</head>
<body>
<div id="myDiv"></div>
</body>
</html>
Attributes of DHTML:
DHTML is characterized by several key attributes that enable its dynamic capabilities:
• Style Properties:
o Attributes like color, background-color, font-size, etc., are modified using CSS.
• Element Positioning:
o Attributes such as position, top, left, z-index allow precise control over the layout.
o Attributes like visibility and display determine whether elements are visible or hidden.
• Event Attributes:
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
body {
background-color: lightgray;
h1 {
color: blue;
p{
font-size: 20px;
</style>
</head>
<body>
<h1>Welcome to My Page!</h1>
</body>
</html>
In this example, the CSS styles defined in the <style> tag will only apply to this specific HTML
document.
1. ........................ enables authors to create visually compelling Web sites without the
overhead of server-side programs or complicated sets of controls to achieve special
effects.
Answer: B. DHTML
Meaning: DHTML (Dynamic HTML) allows authors to create interactive and animated web
57
pages using a combination of HTML, CSS, and JavaScript without relying heavily on server-side
programming.
3. .......................... is the weakest link in DHTML as many of the browsers do not support the
DOM functionality.
Answer: C. DOM (Dynamic Object Model)
Meaning: The DOM is a programming interface that browsers use to structure and manipulate
HTML and XML documents. Its inconsistent support across different browsers can be a
limitation for DHTML applications.
4. CSS was first developed in ................................., as a way for Web developers to define
the look and feel of their Web pages.
Answer: A. 1️997
Meaning: CSS was introduced in 1997 to provide web developers with a standardized way to
style web pages, enabling better separation of content and presentation.
6. .......................... style sheet is used when you want to define styles for the current page.
Answer: B. Embedded
Meaning: An embedded (or internal) style sheet is defined within the <style> tags in the HTML
document, applying styles specifically to that page.
7. An ...................................... style sheet is a separate file where you can declare all the
styles that you want to use on your website.
Answer: A. External
Meaning: An external style sheet is a standalone CSS file that can be linked to multiple HTML
pages, allowing for centralized control of the website's design.
58
10. The DIV elements define ......................... divisions in your web page.
Answer: B. Logical
Meaning: <div> elements are used to create logical divisions in a web page, allowing
developers to structure content semantically.
11. The DIV element gives you the chance to define the ........................ of whole sections of
the HTML.
Answer: A. Style
Meaning: The <div> element allows you to apply styles to entire sections of content, facilitating
layout control and styling.
12. CSS would not be very useful if it did not allow you to have many different types of formats
for a single HTML tag.
Answer: A. True
Meaning: CSS is valuable because it enables multiple styles to be applied to the same HTML
element, allowing for varied presentations and responsive designs.
13. For using classes, you are not required to add an extension to the typical CSS code.
Answer: B. False
Meaning: While using classes in CSS does not require an extension, they must be properly
defined in the CSS file to work effectively in the HTML.
15. The World Wide Web Consortium or the W3C is currently implementing standards for
DHTML technologies.
Answer: A. True
Meaning: The W3C is responsible for developing web standards and guidelines, including
those that pertain to DHTML technologies, ensuring consistency and interoperability across
the web.
• Web Development: They are essential for creating interactive and dynamic web pages. For
example, JavaScript is commonly used to enhance user experiences on websites.
• Automation: Scripting languages automate repetitive tasks, making processes faster and
reducing human error. For instance, shell scripts can automate system administration tasks.
59
• Rapid Development: They allow developers to write code quickly and easily. The syntax of
scripting languages is often simpler than compiled languages, enabling faster prototyping.
• Integration: Scripting languages can easily integrate with other applications and services,
facilitating data exchange and communication between different systems.
• Origin (1️995): JavaScript was created by Brendan Eich while working at Netscape
Communications Corporation. It was initially called Mocha, later renamed to LiveScript, and
finally became JavaScript.
• Standardization (1️997): JavaScript was standardized under the name ECMAScript by the
European Computer Manufacturers Association (ECMA). This standardization helped ensure
consistent implementation across different browsers.
• Growth: Over the years, JavaScript has evolved significantly, with major updates like
ECMAScript 5 (2009), which introduced features like strict mode, and ECMAScript 6 (2015),
which added classes, modules, and arrow functions.
• Popularity: JavaScript became one of the most popular programming languages due to the
rise of web applications. It is now used not only in the browser but also on servers (Node.js)
and in mobile app development (React Native).
Platform Can run on any platform with JVM Runs in web browsers or servers (Node.js)
Object-
Yes, class-based Yes, prototype-based
Oriented
JavaScript has several data types, categorized into two groups: primitive and non-primitive.
60
1. Number: Represents both integer and floating-point numbers.
5. Undefined: Represents a variable that has been declared but not assigned a value.
6. Symbol: A unique and immutable value, often used as object property keys.
1. Object: A complex data structure that allows storing multiple values as key-value pairs.
To include JavaScript in an HTML document, you can use the <script> tag. Here’s how you can do it:
Inline JavaScript:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>Hello, World!</h1>
<script>
alert("Welcome to my website!");
</script>
61
</body>
</html>
External JavaScript:
You can also link to an external JavaScript file using the src attribute.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>
• Inside <head>: It loads before the content. If it contains DOM manipulations, it might cause
errors as elements may not be loaded yet.
• Before </body>: This is the preferred method, as it ensures that the HTML elements are loaded
before the script runs.
JavaScript is a programming language that runs in web browsers, and its compatibility can vary across
different browsers. Here's a breakdown of what you need to know:
• Cross-Browser Support: Different browsers (like Chrome, Firefox, Safari, and Edge) may
interpret JavaScript code differently. This can lead to inconsistencies in how web pages
behave.
• Feature Support: New features (like ES6, ES7, etc.) are introduced in JavaScript, but not all
browsers support them at the same time. For example, older browsers may not support newer
syntax or APIs.
o Polyfills: These are pieces of code that provide functionality in browsers that do not
support certain features.
62
o Transpilers: Tools like Babel can convert modern JavaScript into a version that is
compatible with older browsers.
• Testing: Always test your web applications in multiple browsers to ensure they function
correctly.
The name "JavaScript" can be a bit misleading, and here's the story behind it:
• Origin of the Name: JavaScript was originally named "Mocha" and then "LiveScript" before it
was finally branded as "JavaScript" in 1995.
• Marketing Strategy: At the time, Java was a popular programming language, and naming it
"JavaScript" helped increase interest and adoption. However, the two languages are quite
different in their design and use cases.
• Relationship with Java: Despite the name, JavaScript is more similar to languages like C and
Scheme. It's a lightweight, interpreted language primarily used for web development.
8. Typecasting in JavaScript
Typecasting in JavaScript refers to converting one data type to another. JavaScript is a loosely typed
language, meaning variables can hold any type of data. Here’s how typecasting works:
• Implicit Type Conversion (Coercion): This happens automatically when you use operators.
For example:
• Explicit Type Conversion: You can also manually convert types using functions:
9. Arrays in JavaScript
Arrays are used to store multiple values in a single variable. They are very flexible and powerful in
JavaScript:
• Accessing Elements: Each element can be accessed using its index (starting from 0):
• Array Methods: JavaScript provides many methods for working with arrays:
JavaScript provides methods to convert numbers between different bases (like binary, octal, decimal,
and hexadecimal):
▪ Example:
o parseInt(string, base): This function parses a string and returns an integer of the
specified base.
▪ Example:
The backslash in JavaScript serves as an escape character. It allows you to include special
characters in strings that would otherwise be difficult to represent. For example:
• Escape Sequences: It is used to escape characters like quotes or newlines. For instance:
Example:
If you want to create a string that includes both single and double quotes, you can write:
64
1️2️. What is an Operator?
Defining Operators
An operator is a special symbol that performs operations on variables and values. Operators can be
thought of as tools that allow you to manipulate data.
Types of Operators:
• Arithmetic Operators: Used for mathematical calculations (like addition and subtraction).
• Comparison Operators: Used to compare two values (like checking if they are equal).
Example:
In the expression 5 + 3, the + symbol is an operator that adds the two numbers together.
Works with integer and floating- Works primarily with integer types
Input Types
point numbers. (binary values).
Example Calculating the sum of expenses Setting flags, masking bits, or shifting
Application or determining an average score. values for efficiency.
65
Feature Arithmetic Operators Bitwise Operators
Visual Operates on numbers directly as Operates on binary digits (0s and 1️s)
Representation we see them. behind the scenes.
Arithmetic Operators
• Examples:
Bitwise Operators
• Examples:
o NOT (~): Flips the bits (0s to 1️s and vice versa).
o Left Shift (<<): Moves bits to the left, filling with zeros.
o Right Shift (>>): Moves bits to the right, filling with zeros or sign bits.
Summary
• Arithmetic operators are essential for basic mathematical operations, suitable for high-
level calculations in various fields. They operate directly on the numbers as we perceive
them.
• Bitwise operators work on the underlying binary representations of numbers, allowing for
precise control over data and efficient manipulation of bits, which is particularly valuable
in low-level programming tasks.
66
1️4. Why Comparison Operators Are Used?
Comparison operators are used to compare two values and determine their relationship. They help
you evaluate conditions in programming.
• Strict Equal to (===): Checks if two values are equal and of the same type.
Example:
In a game, you might check if a player’s score is greater than a certain value to determine if they win.
Logical operators are used to combine multiple conditions or expressions. They help in making
decisions based on multiple criteria.
1. It’s raining.
• AND: You can go outside only if it’s not raining AND you have an umbrella.
• OR: You can go outside if it’s not raining OR you have an umbrella.
67
The === operator in JavaScript is known as the strict equality operator. It compares two values to
determine if they are equal, and it checks both the value and the data type. Here’s how it works:
• Type Checking: It does not perform type coercion. This means if you compare a number to a
string, it will return false unless they are of the same type.
o Example:
In summary, === ensures that both the value and type are exactly the same, making it a safer choice
for comparisons.
The delete operator is used to remove properties from an object in JavaScript. When you use delete, it
permanently removes the specified property, and it can’t be restored.
• Key Points:
o If you try to delete a property that does not exist, it won’t throw an error; it will simply
return true.
For example, if you have an object representing a car and you want to remove the color property, you
would use the delete operator.
Boolean operators are logical operators that are used to combine or modify boolean values (true or
false). In JavaScript, the main Boolean operators are:
• NOT (!): Reverses the boolean value (true becomes false and vice versa).
Use Cases:
• You can use these operators in conditions (like in if statements) to control the flow of your
program based on multiple conditions.
In this expression, JavaScript performs operations based on the types of the values involved:
68
2. The second value is a number (2).
When you add a string to a number, JavaScript converts the number to a string and concatenates
them. So, the evaluation happens as follows:
Similar to the previous question, this expression involves both numbers and a string:
An expression in JavaScript is any piece of code that evaluates to a value. This can be a combination
of values, variables, operators, and function calls that JavaScript interprets and produces a result.
Types of Expressions:
Importance: Expressions are fundamental building blocks in programming as they can be used
wherever a value is expected, like in conditions, assignments, and function arguments.
1. Developed under the name ..........................., Live Script was the official name for the
language when it first shipped in beta releases of Netscape Navigator 2️.0.
Answer: C. Mocha
Meaning: Mocha was the original name for JavaScript before it was renamed to LiveScript and
later to JavaScript. It was part of the early development of web programming.
69
2. The change of name from ........................... to JavaScript roughly coincided with
Netscape adding support for Java technology in its Netscape Navigator web browser.
Answer: B. LiveScript
Meaning: LiveScript was the name before JavaScript, and the renaming reflected the
integration of Java technologies into web development.
7. In JavaScript, ........................... tags can be inserted into three places: in between the two
BODY tags, in between the two HEAD tags, and as a link to an external file, also in the
HEAD section.
Answer: A. SCRIPT
Meaning: <script> tags are used to embed JavaScript code directly within HTML documents or
link to external JavaScript files.
8. If your JavaScript references any of the web pages ..........................., there may be a
slight delay in the fancy effects you want to apply, or it may just not work at all.
Answer: C. elements
Meaning: JavaScript relies on specific elements within the web page; if they are not properly
loaded or referenced, the intended effects may not function.
10. Add an HTML comment tag ................before the first JavaScript statement, and a —> (end
of comment) after the last JavaScript statement.
Answer: B. <!
70
Meaning: The correct way to add comments in HTML is to use <!-- to start the comment and --
> to end it.
11. .......................... data types are the types that can be assigned a single literal value.
Answer: D. Primitive
Meaning: Primitive data types (such as numbers, strings, and booleans) represent single
values and are not objects.
12. .......................... are rows of characters enclosed in either double or single quotes.
Answer: A. String Literals
Meaning: String literals are sequences of characters used in programming, typically enclosed
in quotes to define them.
13. To get the value of the ........................... element, we can use the value property of the
text input object.
Answer: C. Text Input
Meaning: The value property retrieves the current input value from text fields in a web form.
15. ........................... allows you to access a specific value as if it were of a different type.
Answer: D. Type Casting
Meaning: Type casting is the process of converting a variable from one data type to another to
perform operations.
17. An ........................... is a special variable, which can hold more than one value at a time.
Answer: Array
Meaning: An array is a data structure that allows you to store multiple values in a single
variable, organized in an indexed format.
18. Each element in the array has its own ........................... so that it can be easily accessed.
Answer: ID
Meaning: Each element in an array can be accessed using its index (ID), which is its position
within the array.
19. ........................... operators test to see if two variables relate to each other in the
specified way.
Answer: Comparison
Meaning: Comparison operators evaluate relationships between values (such as equality or
inequality).
71
20. ........................... is called the Bitwise NOT Operator, which is a unary operator and
operates by reversing all bits in the operand.
Answer: ~
Meaning: The Bitwise NOT operator (~) inverts the bits of its operand, turning 1s into 0s and
vice versa.
21. The operator ........................... is the multiply AND assignment operator; it multiplies the
right operand with the left operand and assigns the result to the left operand.
*Answer: =
Meaning: The *= operator combines multiplication and assignment into one operation,
updating the left operand with the product.
23. ........................... Operator first evaluates an expression for a true or false value and then
executes one of the two given statements depending upon the result of the evaluation.
Answer: Conditional
Meaning: Conditional operators (such as if) control the flow of execution based on boolean
expressions.
24. The ........................... is a unary operator that is placed before its single operand, which
can be of any type.
Answer: Type of
Meaning: The typeof operator is used to determine the data type of a variable or expression.
25. The ........................... of operators determines the order they are applied when evaluating
an expression.
Answer: Precedence
Meaning: Operator precedence defines the hierarchy of operations in an expression, affecting
the order in which they are computed.
26. The operator ........................... checks if the value of two operands is equal or not; if
values are not equal, then the condition becomes true.
Answer: !=
Meaning: The != operator evaluates to true if the two operands are not equal, regardless of
their data types.
27. Due to the possibly confusing nature of pre-and post-increment behavior, code can be
easier to read if the ........................... operators are avoided.
Answer: Increment
Meaning: Pre-increment (++var) and post-increment (var++) operators can lead to ambiguity;
avoiding them can improve code clarity.
72
Meaning: The Bitwise OR operator (|) compares each corresponding bit of two integers and
returns a new integer with bits set to 1 where either input has a 1.
29. An ........................... is any valid set of literals, variables, operators, and expressions that
evaluates to a single value.
Answer: Expression
Meaning: An expression is a combination of values and variables that can be computed to
yield a result.
33. Variables that have not been assigned a value are undefined, and cannot be used without
a ........................... error.
Answer: Run-Time
Meaning: Accessing undefined variables leads to run-time errors, as the interpreter cannot
reference a variable that hasn't been initialized.
Both if-else and switch statements help in decision-making in a program. They allow the program to
take different actions based on conditions.
If-Else Statement:
73
Example Usage:
Imagine an online shopping website. If the total bill is above ₹1000, the customer gets a discount. If
not, they pay the full amount.
Switch Statement:
• The switch statement is used when a variable needs to be checked for multiple possible
values.
• It helps in cases where multiple if-else statements can make the code too long.
• Each case represents a possible value and contains specific actions to perform.
• It is mainly used when we have fixed choices to check (e.g., days of the week, menu options).
Example Usage:
A restaurant menu can use switch to display prices based on what the user selects (Pizza, Burger, or
Pasta).
Break Statement:
• After breaking out, the program jumps to the next statement after the loop.
• Used when we want to exit a loop immediately upon meeting a certain condition.
Example Usage:
Imagine you are searching for a book in a library. As soon as you find it, you stop looking and leave. The
break statement works in the same way.
Continue Statement:
• Instead of stopping the loop, continue skips the current iteration and moves to the next one.
• It is useful when you want to ignore specific values but still continue looping.
Example Usage:
In a classroom, a teacher is checking student marks. If a student was absent (marked "A"), the
teacher skips grading them but continues checking other students.
Both loops are used to repeat a set of instructions, but they work in different ways.
For Loop:
• Best for situations like counting numbers, printing tables, or iterating over lists.
Example Usage:
Imagine you are counting from 1️ to 1️0. You know in advance that you need 1️0 steps, so a for loop is
ideal.
While Loop:
• Best for user input-based loops or situations where stopping depends on dynamic
conditions.
Example Usage:
A mobile phone keeps checking for incoming calls while it is powered on. The number of checks is
unknown, so a while loop is better.
While Loop:
• If the condition is false from the start, the loop never runs.
Example Usage:
A bank only allows transactions if an account has sufficient balance. If the condition is not met, the
transaction does not proceed.
Do-While Loop:
Example Usage:
A vending machine asks "Do you want another item?" after each purchase. Even if you press "No",
the machine asks at least once before stopping.
Statement: “The switch case conditional statement is used to test all of the possible outcomes for
the application being designed.”
75
The switch case statement is very helpful when dealing with multiple predefined choices. However,
it does not cover all possible outcomes in every situation.
Example Consideration:
Imagine a traffic light system with Red, Yellow, and Green. A switch case is perfect because there
are only three fixed states.
However, if a weather app needs to check temperature ranges, a switch case would not be
useful—an if-else statement would work better.
1. ........................... statements give the JavaScript code you are writing the ability to make
decisions or perform single or multiple tasks.
Answer: A. Conditional
Meaning: Conditional statements allow the execution of different code blocks based on
whether a specified condition evaluates to true or false, enabling decision-making in
programming.
3. The ........................... conditional statement is used to test all of the possible outcomes
for the application you are designing.
Answer: A. Switch case
Meaning: The switch statement is used to select one of many code blocks to execute, based
on the value of an expression, effectively testing multiple conditions.
4. The ........................... loop is used when you know in advance how many times the script
should run.
Answer: A. For
Meaning: The for loop is a control structure that allows for repeated execution of a block of
code a specified number of times, making it useful for scenarios where the iteration count is
known beforehand.
76
5. The ........................... loop loops through a block of code while a specified condition is
true.
Answer: C. While
Meaning: The while loop continues to execute a block of code as long as the specified
condition remains true, making it suitable for situations where the number of iterations is not
known in advance.
6. The ........................... loop will execute the block of code ONCE, and then it will repeat
the loop as long as the specified condition is true.
Answer: B. Do-while
Meaning: The do-while loop guarantees that the code block runs at least once before the
condition is tested, allowing for situations where the initial execution is necessary.
7. The ........................... statement will break the loop and continue executing the code that
follows after the loop (if any).
Answer: D. Break
Meaning: The break statement is used to exit a loop prematurely, allowing the program to
continue with the next line of code following the loop.
8. The ........................... statement will break the current loop and continue with the next
value.
Answer: C. Continue
Meaning: The continue statement skips the rest of the code inside the loop for the current
iteration and proceeds to the next iteration of the loop.
9. A/An ........................... dialog box is mostly used to give a warning message to the users.
Answer: A. Alert
Meaning: An alert dialog box is a simple popup that displays a message to the user, typically
used for warnings or important notifications.
10. The ........................... dialog box is very useful when you want to pop up a text box to get
user input.
Answer: D. Prompt
Meaning: A prompt dialog box displays a message along with an input field, allowing users to
enter data, making it useful for gathering information.
11. A ........................... dialog box is mostly used to take the user's consent on any option.
Answer: B. Confirmation
Meaning: A confirmation dialog box is used to ask users for their consent or decision before
proceeding with an action, typically providing options like "OK" or "Cancel."
12. In .......................... loop, you know in advance how many times the script should run.
Answer: B. For
Meaning: The for loop is specifically designed for situations where the number of iterations is
predetermined, making it easy to manage the loop's execution.
13. The ........................... gives the JavaScript code you are writing the ability to make
decisions or perform single or multiple tasks.
Answer: Control statement
77
Meaning: Control statements include constructs like if, switch, and loops that enable
decision-making and control the flow of execution in JavaScript.
14. To test all of the possible outcomes for the application being designed, the
........................... conditional statement is used.
Answer: Switch-case
Meaning: The switch-case statement is effective for evaluating multiple potential conditions or
outcomes based on a single expression.
15. In case of the ........................... loop, the block of code will execute ONCE, and then it will
repeat the loop as long as the specified condition is true.
Answer: Do-while
Meaning: The do-while loop ensures that the code within it is executed at least once before
checking the condition for further iterations.
JavaScript is a powerful language that consists of functions and statements to perform different
tasks. Let’s break them down in a simple and creative way!
Tabular Comparison
Can be called multiple times to execute Usually runs once unless controlled by
Reusability
the same logic. loops or conditions.
Input & Output Can take inputs (parameters) and return Mostly executes an action without
outputs. returning anything.
78
Feature Function Statement
Can be simple or very complex, containing Usually simple, performing one task at
Complexity
many statements inside. a time.
Explanation of Functions
What is a Function?
A function is like a machine in a factory. You put something inside, it processes it, and then it gives an
output. Functions help in organizing code, making it reusable and efficient.
Explanation of Statements
What is a Statement?
A statement is a single instruction that tells JavaScript to do something. It is like a command given to
a computer.
79
How Do Statements Work?
1⃣ The browser reads JavaScript line by line.
2⃣ Each statement is executed immediately.
3⃣ Based on the statement, JavaScript might store values, make decisions, or repeat actions.
Final Thoughts
Built-in functions in JavaScript are predefined functions that are already available for use without
writing any extra code. These functions help developers perform common tasks easily, such as
manipulating strings, working with numbers, and handling arrays.
String Functions → Help in working with text, like converting letters to uppercase or finding the
length of a word.
Math Functions → Used for calculations, like finding the square root or rounding a number.
Array Functions → Allow operations on lists, like sorting or filtering data.
Date Functions → Help in working with dates, like getting the current day or time.
80
Feature Built-in Functions User-Defined Functions
length (for strings), round (for Custom functions like calculating discounts
Examples
numbers), sort (for arrays). or generating greetings.
Modification Cannot be modified by the user. Fully customizable based on user needs.
In Simple Words: Built-in functions are predefined helpers, while user-defined functions are
custom-made solutions for specific problems.
Dialog boxes in JavaScript are pop-up windows that appear on the screen to interact with users. They
help in displaying messages, taking input, or confirming actions before continuing with a task.
User Input Does not take any input. Takes user input in a text box.
81
Feature Alert Box Prompt Box
In Simple Words:
✔ Alert Box = Just shows a message and waits for OK.
✔ Prompt Box = Asks a question, lets the user type a response, and then presses OK or Cancel.
A Confirm Dialog Box is a special type of popup message that appears on a web page to ask the user
for confirmation before performing an action.
Takes User Permission – It asks the user to either accept or decline an action.
Prevents Mistakes – Useful in situations where the action cannot be undone (e.g., deleting a
file).
Improves User Experience – Provides an interactive decision-making process.
Two Response Options – The user can confirm (OK) or cancel (Cancel) the action.
Used for Critical Actions – Example: "Are you sure you want to log out?"
Deleting files or data – “Do you really want to delete this item?”
Form submission – “Are you sure you want to submit this form?”
Logging out of an account – “Do you want to log out now?”
Removing an item from a cart – “Are you sure you want to remove this item?”
Both Confirm and Alert dialog boxes are used to communicate messages to the user, but they serve
different purposes.
User Response Offers two buttons: OK & Cancel Offers only one button: OK
User Decision User can accept or reject the action User can only acknowledge the message
82
Feature Confirm Dialog Box Alert Dialog Box
Alert Box – Just displays a message and waits for the user to click OK.
Confirm Box – Asks the user a Yes/No type question, allowing them to confirm or cancel an
action.
Use Alert Box – When you just want to inform the user about something.
Use Confirm Box – When you need the user’s decision before proceeding.
1. To keep the browser from executing a script when the page loads, you can put your script
into a .....................
Answer: A. function
Meaning: Wrapping your script in a function allows you to control when it executes, preventing
it from running automatically on page load.
3. An ........................... function saves us from rewriting the same code again and again and
helps us to make our application smaller.
Answer: D. user-defined
Meaning: A user-defined function is created by the programmer to encapsulate code that can
be reused throughout the application, improving efficiency.
5. .......................... variables exist only inside a particular function hence they have Local
Scope.
Answer: C. local
Meaning: Local variables are declared within a function and are only accessible within that
function, preventing external access and avoiding name conflicts.
83
6. An ........................... dialog box is mostly used to give a warning message to the users.
Answer: B. alert
Meaning: An alert dialog box is used to display a message to the user, typically to inform them
of an important piece of information or warning.
7. The ........................... dialog box is very useful when you want to pop-up a text box to get
user input.
Answer: A. prompt
Meaning: A prompt dialog box asks the user for input and displays a text box where they can
enter their response.
8. ……………… are blocks of JavaScript code that perform a specific task and often return a
value.
Answer: C. Functions
Meaning: Functions in JavaScript are reusable blocks of code designed to perform a specific
task and can return a value when called.
9. ………….. are a standard technique via which control data can be passed to a function.
Answer: D. Parameters
Meaning: Parameters are variables listed as part of a function's definition, allowing values to
be passed into the function when it is called.
10. JavaScript provides the ability to pick up user input or display a small amount of text to
the user by using …………….
Answer: B. dialog boxes
Meaning: Dialog boxes in JavaScript are used to interact with users, allowing for input or
display of messages.
11. A function contains ……… that will be executed by an event or by a call to the function.
Answer: A. code
Meaning: A function consists of executable code that performs tasks when invoked either by
user action or programmatically.
13. A ……………. function saves us from rewriting the same code again and again and helps us
to make our application smaller.
Answer: D. user-defined
Meaning: A user-defined function allows for code reuse, which simplifies the program and
makes it easier to manage.
14. …………… can be used to raise an alert, or to get confirmation on any input or to have a
kind of input from the users.
Answer: B. dialog boxes
Meaning: Dialog boxes are used for various user interactions, such as alerts, confirmations,
and input requests.
84
15. A. parseFloat() function takes a string as a parameter and parses it to a floating point
number.
Answer: A. parseFloat()
Meaning: The parseFloat() function converts a string representation of a number into a
floating-point number, allowing for numerical operations.
The Document Object Model (DOM) is a programming interface that represents a web page as a
structured tree of objects. It allows programming languages (like JavaScript) to interact with and
manipulate the content, structure, and style of a webpage dynamically.
The Document Object Model (DOM) is a tree-like representation of an HTML or XML document. It
provides a structured way to access, modify, and manage webpage elements using scripting
languages like JavaScript.
Imagine DOM as a blueprint of a webpage that helps browsers understand and manipulate the
structure of HTML elements.
The DOM Interface is a collection of objects and methods that define how programs can interact
with the document.
The DOM Interface acts as a bridge between web documents and programming languages.
85
3. How do you define DOM?
This hierarchical representation makes it easy for developers to interact with elements dynamically.
A node in the DOM is a single point in the document tree that represents an element, attribute, or text.
Types of Nodes:
Element Nodes – Represent HTML elements (<p>, <h1>, <img>, etc.).
Text Nodes – Contain actual text inside elements.
Attribute Nodes – Represent attributes like id, class, href, etc.
Comment Nodes – Store comments inside HTML (<!-- This is a comment -->).
Example: In <h1 class="title">Hello</h1>, the Element Node is <h1>, the Text Node is "Hello",
and the Attribute Node is class="title".
A node tree is a hierarchical structure where elements, attributes, and text are organized in a parent-
child relationship.
• Grandparent = <html>
• Parent = <body>
86
DOM provides properties (to get/set values) and methods (to perform actions).
Common Properties:
document.title – Gets/sets the webpage title.
document.body – Accesses the <body> tag.
element.innerHTML – Modifies an element's content.
element.className – Changes the class of an element.
Common Methods:
getElementById() – Finds an element by ID.
getElementsByClassName() – Selects elements by class.
querySelector() – Finds the first matching element.
createElement() – Creates a new element.
Think of these as commands that help manipulate a webpage like a remote control.
HTML elements have built-in properties that define their behavior and appearance.
Example Analogy:
An HTML element is like a box, and these properties define its label (id), appearance (className),
and contents (innerHTML).
The document object represents the entire HTML page and provides properties to interact with it.
Example: Just like a book has a title, chapters, and content, the document object organizes
webpage data.
Example Representation:
Imagine the following HTML:
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>
Document
├── <html>
│ ├── <head>
│ ├── <body>
Conclusion
Both onMouseOver and onMouseOut are mouse events in web development that detect when a user
moves their cursor over an element. However, they behave differently in specific scenarios. Let's
break them down in a tabular format for better clarity.
88
Comparison Table: onMouseOver vs. onMouseOut
Activates when the cursor enters an Activates when the cursor leaves an
Triggering Condition
element element
Highlights or changes an element when Removes the effect when the cursor
Effect
hovered moves away
Works with Child Yes, it also triggers when moving Yes, it triggers when leaving the
Elements? between child elements element entirely
Showing a tooltip when hovering over a Hiding the tooltip when the cursor
Example Use Case
button leaves the button
What is onMouseOver?
This event fires when the mouse pointer enters an element or any of its child elements.
It is commonly used to create hover effects such as color changes, pop-up descriptions, or
dropdown menus.
If the element has nested elements (children), the event keeps firing when moving between
them.
What is onMouseOut?
This event fires when the mouse pointer leaves an element or any of its child elements.
It is mostly used to remove hover effects when the cursor is no longer over an element.
If an element has nested child elements, the event triggers only when the mouse leaves the
entire parent element, not when moving between children.
Real-Life Analogy
• onMouseOver → When you walk into a store, the staff greets you.
• onMouseOut → When you leave the store, they stop interacting with you.
This is exactly how these two events work—one welcomes you when you enter, and the other says
goodbye when you leave!
89
1️1️. What is the History Object Function in JavaScript?
The History object allows us to navigate through the pages a user has visited in their browser session.
It helps in managing browser history without reloading the page.
• Check History Length → Tells how many pages exist in the history stack.
The history object is useful in single-page applications (SPA) where users can navigate without
refreshing the page.
The Location object provides information about the current page URL and allows redirection to
another page.
The Location object is mainly used for page navigation, redirection, and getting URL details.
The DOM (Document Object Model) represents a web page as a structured tree-like model where
elements (like text, images, buttons) can be added, removed, or modified.
In JavaScript, an object is like a container that holds multiple pieces of related information.
• Create and Assign at the Same Time → Define properties when creating an object.
Objects help in organizing data in a meaningful way and improve code efficiency.
• Using Object Literals → The simplest way to define an object with key-value pairs.
Objects are building blocks in JavaScript that help manage related data efficiently.
NaN stands for "Not-a-Number" and is a special value that appears when a mathematical operation
fails.
91
The DOM acts as a bridge between JavaScript and HTML, allowing JavaScript to modify the webpage
dynamically.
Functions of DOM:
The Screen object provides details about the user’s display screen.
• availWidth & availHeight → Shows the usable screen size excluding taskbars.
The Screen object is useful for creating responsive designs and optimizing website display settings.
The Navigator object provides information about the browser and device.
The Navigator object helps in detecting browser compatibility, network status, and user
preferences.
Conclusion
92
JavaScript has various built-in objects like History, Location, Document, Screen, and Navigator
that make web development more dynamic and interactive. These objects help in managing
browser history, interacting with the page, getting device info, and more.
2. The DOM Core represents the functionality used for ........................... documents.
Answer: B. XML
Meaning: The DOM Core provides an interface for manipulating XML documents, allowing
access to the document's structure and content.
4. The M in DOM stands for Model, but it could just as easily stand for ...........................
Answer: D. Map
Meaning: While "Model" is the standard interpretation, "Map" could conceptually represent
how the DOM provides a mapped representation of the document structure.
5. A ........................... is an interface from which a number of DOM types inherit, and allows
these various types to be treated (or tested) similarly.
Answer: A. Node
Meaning: A Node is a fundamental building block of the DOM, representing any object in the
document tree, allowing for consistent manipulation of different types of objects.
6. The ........................... tag is used to include objects such as images, audio, videos, Java
applets, ActiveX, PDF, and Flash into a webpage.
Answer: C.
Meaning: The <object> tag is used to embed multimedia elements and external resources into
HTML documents.
93
9. ........................... method is used to import a node from another document.
Answer: B. importNode()
Meaning: The importNode() method allows for the copying of a node from one document to
another, preserving its attributes and child nodes.
11. Every element on a ........................... has certain events which can trigger a JavaScript.
Answer: C. Web page
Meaning: Elements within a web page can respond to various events, enabling interactivity
through JavaScript.
12. The ........................... event is often used to check the visitor’s browser type and browser
version, and load the proper version of the web page based on the information.
Answer: C. onLoad
Meaning: The onLoad event is fired when a document has finished loading, often used to
execute scripts or load resources based on the browser's capabilities.
13. The ........................... event is used to validate ALL form fields before submitting it.
Answer: D. onSubmit
Meaning: The onSubmit event occurs when a form is submitted, allowing for validation of form
fields to ensure all required information is correctly filled out.
14. onMouseOver and onMouseOut are often used to create “...........................” buttons.
Answer: B. Animated
Meaning: These events are used to create interactive effects, such as changing button
appearance when a user hovers over or leaves the button area.
15. ........................... is a frame set, document, or form object such as a text field loses the
focus for input.
Answer: B. Blur
Meaning: The blur event occurs when an element loses focus, typically used for input fields to
trigger validation or changes in appearance.
16. For a ........................... window, the parent and top properties refer to the window itself.
Answer: top-level
Meaning: In a top-level window, both parent and top refer to the window object itself,
indicating that it is not contained within another frame.
17. ........................... method decodes a string of encoding data using base-64 encoding.
Answer: A. Atob
Meaning: The Atob() method decodes a base-64 encoded string, converting it back to its
original format.
19. ........................... contains information about the version, mime type, and what plug-ins
users have installed of Navigator in use.
Answer: Navigator objects
Meaning: The Navigator object provides information about the user's browser, including its
version and capabilities.
24. The ........................... property specifies the number of entries in the history object.
Answer: length
Meaning: The length property of the History object indicates how many entries are stored in
the session history.
26. ........................... is the part of the URL that is used to point to a particular part of a page
where a named anchor is.
Answer: Hash
Meaning: The hash portion of a URL (preceded by #) refers to a specific location within a web
page, often used for named anchors.
95
28. The JavaScript ........................... is the container for all HTML HEAD and BODY objects
associated within the HTML tags of an HTML document.
Answer: Document object
Meaning: The Document object represents the entire HTML document and serves as the entry
point to the DOM for accessing and manipulating elements.
29. ........................... property sets the background color of the web page.
Answer: bgColor
Meaning: The bgColor property can be used to set the background color of the document body
in HTML.
30. ........................... property specifies the text color attribute set in the tag.
Answer: fgColor
Meaning: The fgColor property specifies the foreground (text) color for content within the body
of an HTML document.
In JavaScript, events are actions or occurrences that happen in a web page, which the browser can
recognize and respond to. Events are triggered by user interactions like clicking, typing, hovering, or
even page loading.
Examples of events:
Clicking a button
Pressing a key on the keyboard
Moving the mouse over an element
Loading a webpage
Events help make web pages interactive and responsive. Without events, web pages would be static
and unresponsive to user actions.
96
3. How to use onMouseOver and onMouseOut events?
These two events are mainly used to detect when a user moves their mouse over an element and
when they move the mouse away from it.
onMouseOver: This event is triggered when the mouse pointer enters an element.
onMouseOut: This event is triggered when the mouse pointer leaves the element.
Common uses:
Highlighting text when hovered
Changing an image when hovered
Showing tooltips when hovered
Changing the background color of an element can improve the visual appearance of a webpage. It is
often used in response to events like clicking a button, hovering over an element, or submitting a form.
These events are related to the loading and unloading of a webpage in the browser.
onLoad: This event occurs when the webpage finishes loading completely. It ensures that scripts
or images are fully loaded before executing any action.
onUnload: This event occurs when the user leaves the webpage or closes the browser tab. It is
often used to save user progress or show a warning before exiting.
Common uses:
Displaying welcome messages when a page loads
Tracking user activity on the page
Showing exit warnings when leaving the page
These terms refer to the functions or actions that are executed when the onLoad or onUnload events
occur.
onLoad Calls: These are the actions triggered when the page loads.
onUnload Calls: These are the actions triggered when the page is closed or navigated away from.
97
Examples of usage:
Preloading images when the page loads
Saving form data before exiting the page
Sending analytics data when a user leaves the site
The onBlur event is triggered when an element loses focus. This is mainly used in form fields where
users enter data.
Common uses:
Validating input fields when a user moves to another field
Hiding tooltips when a user clicks outside a text box
Checking if a required field is left empty
The onSelect event is triggered when a user selects text inside an input field or textarea.
Common uses:
Automatically copying selected text
Highlighting selected text in a different color
Showing character count for selected text
The onSubmit event occurs when a form is submitted. It is mainly used for form validation before
sending the data to the server.
Common uses:
Preventing form submission if required fields are empty
Showing success messages after submission
Sending form data to the server
Conclusion:
JavaScript events help create dynamic and interactive web pages. By using events, developers can
control how elements respond to user actions, improving the overall user experience!
Both onMouseOver and onMouseOut are events in web development that respond to mouse actions
on elements. Let's break them down in a table format:
98
Aspect onMouseOver onMouseOut
Triggered when the mouse pointer moves Triggered when the mouse pointer leaves
Definition
over an element. an element.
Activates a specified action while the Activates a specified action when the
Behavior
mouse is over the element. mouse exits the element.
Common Use Change background color, display Revert background color, hide tooltips,
Cases tooltips, enlarge images. shrink images back.
Event Bubbling Yes, it can propagate to parent elements. Yes, it can propagate to parent elements.
Detailed Explanation
What is onMouseOver?
• Definition:
o The onMouseOver event occurs when the mouse pointer hovers over a specific element
on a webpage.
• Usage:
o This event is commonly used to create dynamic effects. For example, when you hover
over a button, it might change color, or an image might enlarge to grab attention.
• Common Effects:
o Image Zoom: An image may zoom in to provide a closer view when hovered over.
What is onMouseOut?
• Definition:
o The onMouseOut event occurs when the mouse pointer leaves the area of an element.
• Usage:
99
o This event is typically used to revert any changes made by onMouseOver. For example, if
you highlighted a button on hover, it would return to its original state when the mouse
moves away.
• Common Effects:
o Reverting Styles: The background color of a button might change back to its original
color.
o Image Reset: An image might return to its normal size when the mouse is no longer
hovering over it.
• Triggering Action:
o onMouseOver is about entering an area, while onMouseOut deals with exiting that
area.
• User Interaction:
Conclusion
Understanding onMouseOver and onMouseOut is essential for creating interactive web experiences.
These events help developers provide visual feedback to users, making websites more engaging and
user-friendly. By using these events creatively, you can significantly improve the interactivity and
usability of your web applications.
1. .............................. are normally used in combination with functions, and the function
will not be executed before the event occurs!
Answer: C. Events
Meaning: Events are actions or occurrences that happen in the browser, such as clicking a
button or loading a page. They are often used to trigger functions, which only execute when the
event occurs.
2. The .............................. and onUnload events are triggered when the user enters or leaves
the page.
Answer: A. onload
Meaning: The onload event occurs when a web page has finished loading, while the onUnload
100
event occurs when a user leaves the page. Both are crucial for managing actions during page
transitions.
3. The ..................................... event is often used to check the visitor’s browser type and
browser version, and load the proper version of the web page based on the information.
Answer: D. onLoad
Meaning: The onLoad event is triggered when a page is fully loaded, making it an ideal point to
check the browser type and load content accordingly.
4. The onFocus, onBlur, and onChange events are often used in combination with
............................ of form fields.
Answer: B. Validation
Meaning: These events are commonly used for validating user input in form fields, ensuring
that the data entered meets specific criteria before submission.
5. The ................................. event is used to validate ALL form fields before submitting it.
Answer: D. onSubmit
Meaning: The onSubmit event is triggered when a form is submitted, allowing for validation of
all fields to ensure that the input is correct and complete.
7. The ............................ property returns the onClick event handler code on the current
element.
Answer: C. onclick
Meaning: The onclick property is used to access the JavaScript code that executes when an
element is clicked, allowing developers to define specific actions for that event.
9. The event object passed to the specified event handler function is a ............................
Answer: A. MouseEvent
Meaning: The MouseEvent is an object that contains information about mouse-related events
(like clicks or movements), which is passed to event handler functions for further processing.
10. A ............................ event occurs when a user selects some of the text within a text or
textarea field.
Answer: C. Select
Meaning: The select event is triggered when a user highlights text in a text input or textarea,
often used for enabling specific functionalities, like copying or modifying the selected text.
11. The .............................. handler executes JavaScript code when a select event occurs.
Answer: D. onSelect event
101
Meaning: The onSelect event handler is activated when text is selected, allowing developers to
run specific JavaScript code in response to that action.
12. The onSubmit event is used to validate ALL form fields before submitting it.
Answer: A. True
Meaning: This statement is true, as the onSubmit event is specifically designed to validate all
form inputs to ensure they are correct before the form is sent.
13. When using the onclick event to trigger an action, there is no need to consider adding this
same action to the onkeydown event.
Answer: B. True
Meaning: This statement is true; if an action is already triggered by the onclick event, adding it
to the onkeydown event is usually unnecessary unless a different user interaction is desired.
14. The onclick property returns the onClick event handler code on the previous element.
Answer: B. False
Meaning: This statement is false; the onclick property pertains to the current element, not the
previous one.
15. MouseEvent is an event object passed to the specified event handler function.
Answer: A. True
Meaning: This statement is true, as the MouseEvent object is indeed passed to event handler
functions to provide information about the mouse actions that triggered the event.
Definition: Forms are sections of a webpage where users can enter information. They are
essential for collecting user data, like names, email addresses, and feedback.
Creation:
• HTML Structure: Forms are created using the <form> tag. This tag acts as a container for
various input elements.
• Input Elements: Inside a form, you can use different types of input fields, like text boxes, radio
buttons, and checkboxes.
Definition: Scripts are pieces of code that can add functionality to your HTML page, like
interactivity and dynamic content.
Usage:
• Script Tag: You can use the <script> tag to include JavaScript. This can be placed in the
<head> section or at the end of the <body> to enhance the page's interactivity.
102
• External Scripts: You can also link to external JavaScript files using the src attribute in the
<script> tag.
Action Attribute:
• Definition: The action attribute specifies where the form data should be sent after submission
(like a server endpoint).
• Example: If your action is set to "submit.php", the data will be sent there when the form is
submitted.
Submit Button:
• Function: The submit button, created with the <input type="submit"> tag, sends the data from
the form to the server defined in the action attribute.
• Appearance: You can customize the button's label to inform users about the action, like
"Submit" or "Send".
Text Field:
• Usage: A text field allows users to input single-line text data, like names or email addresses.
It's created using the <input type="text"> tag.
• Labeling: Always pair it with a label for clarity, so users know what information to enter.
Radio Button:
• Usage: Radio buttons let users select one option from a set. They are created using <input
type="radio">.
• Grouping: To ensure that only one radio button in a group can be selected, they should share
the same name attribute.
Output:
• When a form is submitted, the data entered by the user is sent to the server specified in the
action attribute.
• The output can be displayed back to the user or processed to perform actions, like saving to a
database or sending an email.
• Feedback messages (like "Thank you for your submission!") can enhance user experience.
103
6. How to Create Tables in HTML
Definition: Tables are used to display data in rows and columns, making it easy to read and
compare information.
Creation:
• Use <tr> for table rows, <th> for headers, and <td> for data cells.
Tags:
Purpose:
• Comments are notes written in the code that do not appear on the webpage. They help
developers understand the code better.
• They are added using <!-- comment here --> syntax, making it easier to document complex
sections or remind yourself of important details.
☑️ Checkbox:
• Definition: Checkboxes allow users to select multiple options at once. They are created using
<input type="checkbox">.
• Grouping: Each checkbox should have its unique name attribute to distinguish them when
processing data.
Example: Imagine a survey asking about favorite fruits. You could have checkboxes for options like
"Apple," "Banana," and "Cherry," allowing users to select as many as they like.
104
Font Tag:
• Definition: The <font> tag was used to change text appearance, such as size, color, and
typeface. However, it's outdated and not recommended for modern web design.
• Usage: It was typically used like this: <font color="red" size="4">This is red text.</font>.
Note: Today, it's better to use CSS for styling text to ensure better compatibility and
maintainability.
5. Within the code, which type is used to set the control to a button?
A. button
Explanation: Setting type="button" in the tag creates a button that can trigger a JavaScript
function or submit a form.
6. A text field is placed on a web page using the tag, with the attribute set with a value of
“text”.
C. type
Explanation: The type attribute defines the type of input control, such as text, password,
checkbox, etc.
7. The HTML tag that represents a group of introductory or navigational aids is?
B.
Explanation: The tag is used to group introductory content or navigational links in an HTML
document.
105
8. What are text fields that can span several lines called?
D. Text areas
Explanation: A text area is an input element that allows users to enter multi-line text.
10. What is used when you want to let the visitor select one or more options from a set of
alternatives?
C. Check boxes
Explanation: Checkboxes allow users to select multiple options from a list.
13. What specifies the output value of an input element in an HTML page when it is clicked?
Explanation: The value attribute of an input element defines the data that is sent to the server
when the form is submitted.
14. HTML fields that provide essentially the same functionality as HTML Checkbox Fields are?
Select
Explanation: A select field allows users to choose one or more options from a dropdown list,
similar to checkboxes.
15. Depending on your settings, what can serve the same purpose as radio buttons or
checkboxes?
Drop-down menu
Explanation: A drop-down menu allows users to select one or more options, similar to radio
buttons or checkboxes, but in a compact format.
JavaScript can be used to create a scientific calculator, which performs complex mathematical
operations. Here’s how it works:
• Basic Operations: You can perform addition, subtraction, multiplication, and division using
JavaScript's arithmetic operators.
106
• Advanced Functions: JavaScript includes the Math object, which provides advanced
mathematical functions like square roots, exponents, trigonometric functions (sine, cosine),
and logarithms.
• User Input: You can create forms that allow users to input numbers and select operations,
which the JavaScript code processes to display results.
• Dynamic Updates: Using JavaScript, you can make your calculator update results in real-time
without needing to refresh the page.
In JavaScript, an object is a collection of properties and methods. Here are the key points:
• Properties: These are values associated with the object. For example, a car object may have
properties like color, model, and year.
• Methods: These are functions that belong to the object and can perform actions or
calculations. For example, a car object might have a method called drive() that changes its
state.
• Types of Objects: JavaScript has built-in objects (like Date, Math, and String) and allows you to
create your own custom objects.
The Math object provides several useful methods for mathematical calculations. Some of them
include:
The Math object also includes several properties that are constants:
107
• Math.LN1️0: The natural logarithm of 10, approximately 2.302585.
• Object Literal: You can create an object using curly braces {} and defining properties.
• Constructor Function: You can define a function that serves as a blueprint for creating objects
and use the new keyword.
• Object.create(): You can create a new object with a specified prototype object.
6. User-Defined Objects
User-defined objects are custom objects that you create in your JavaScript code. Here’s what you
should know:
• Customization: You can define properties and methods that are specific to your needs.
• Organization: They help in organizing code by grouping related data and functions together.
• Examples: You might create a Person object with properties like name and age, and methods
like greet().
The Date object in JavaScript is used to work with dates and times. Key points include:
• Properties:
• Methods:
108
• Immutable: Strings in JavaScript are immutable, meaning once created, they cannot be
changed.
• Properties:
• Methods:
o indexOf(): Returns the position of the first occurrence of a specified value in a string.
The Date object has several "get" methods that retrieve specific information about a date:
• getDate(): Returns the day of the month (1-31) for the specified date.
• getDay(): Returns the day of the week (0-6) for the specified date, where 0 is Sunday.
In JavaScript, strings are a fundamental data type used to represent text. Two important methods for
searching within strings are indexOf and lastIndexOf. These methods help locate the position of a
specified substring (a part of the string) within the main string.
Comparison Table
Return Returns the index (position) of the Returns the index of the last occurrence, or -1 if
Value first occurrence, or -1 if not found. not found.
109
Feature indexOf lastIndexOf
Use Useful when you want to find where Useful when you want to find the position of the
Cases a word or character first appears. last occurrence of a word or character.
Detailed Explanation
Purpose
• indexOf: This method is designed to find the first occurrence of a specified substring within a
string. For example, if you have a sentence and want to know where the first occurrence of the
word "apple" appears, indexOf will help you find it.
• lastIndexOf: In contrast, this method finds the last occurrence of a specified substring in the
string. So, if you're interested in knowing where the last "apple" appears in the same sentence,
lastIndexOf will provide that information.
Search Direction
• indexOf: When you use indexOf, the search starts from the left side (the beginning) of the
string and moves towards the right. This means it looks for the substring as it encounters
characters from the start of the string to the end.
• lastIndexOf: Conversely, lastIndexOf begins its search from the right side (the end) of the
string and moves towards the left. It scans backwards, making it effective for locating the final
instance of the substring.
Return Value
• indexOf: If the substring is found, indexOf returns the index (or position) of its first
appearance. If the substring is not present in the string, it returns -1️.
• lastIndexOf: Similarly, lastIndexOf returns the index of the last occurrence of the specified
substring. If it cannot find the substring, it also returns -1️.
Starting Position
• Both Methods: Both indexOf and lastIndexOf can accept an optional parameter that indicates
the starting position for the search. For indexOf, you can start searching from any index in the
string, and for lastIndexOf, you can also specify an index from which the backward search will
start.
Use Cases
110
• indexOf: This method is particularly useful in situations where you want to know where
something first occurs, like when validating user input, checking for keywords in a search, or
parsing text data.
• lastIndexOf: This method is handy when you need to know the last position of a substring,
such as when processing logs, looking for the most recent instance of a word, or when
analyzing a string that may have repeating patterns.
o Answer: C. Math
Meaning: The Math object in JavaScript is a built-in object that provides mathematical
constants and functions, enhancing the basic arithmetic capabilities of the language.
2. The Date object is useful when you want to display a date or use a timestamp in some sort
of calculation.
o Answer: A. Date
Meaning: The Date object allows you to work with dates and times in JavaScript,
providing methods to manipulate date and time values.
3. A Property is a value or set of values (in the form of an array or object) that is a member of
an object.
o Answer: D. Property
Meaning: Properties are characteristics of objects, defined by key-value pairs. They can
hold various types of values, including arrays and other objects.
o Answer: B. Method
Meaning: Methods are functions that belong to an object, allowing the object to
perform actions related to its properties.
5. The String object lets you work with a series of characters and wraps JavaScript’s string
primitive data type with a number of helper methods.
o Answer: C. String
Meaning: The String object provides various methods to manipulate and interact with
strings in JavaScript, such as searching, slicing, and concatenating.
6. The Prototype property allows you to add properties and methods to an object.
o Answer: A. Prototype
Meaning: The prototype property is used to share properties and methods across all
instances of an object, facilitating inheritance in JavaScript.
111
o Answer: D. constructor
Meaning: Math is a built-in object that contains static methods and properties and is
not intended to be instantiated like typical objects.
8. All properties and methods of Math are static and can be called by using Math as an
object without creating it.
o Answer: D. static
Meaning: Static properties and methods belong to the class itself rather than instances
of the class, allowing direct access without instantiation.
o Answer: A. Date()
Meaning: The Date constructor is called to create new Date objects, allowing you to
create instances that represent specific points in time.
11. All user-defined objects and built-in objects are descendants of an object called Object.
o Answer: C. Object
Meaning: In JavaScript, all objects inherit from a common prototype called Object,
which is the base for all objects in the language.
o Answer: B. New
Meaning: The new operator is used to create new instances of objects, invoking
constructors to initialize them.
o Answer: D. Constructor
Meaning: A constructor is a special type of function used to create objects, often
initializing their properties with specific values.
o Answer: B. Variable
Meaning: When an object is created using a constructor, the new object is assigned to a
variable, which holds a reference to that object.
15. The properties assigned to the object are not variables and are not defined with the Var
keyword.
o Answer: A. Var
Meaning: Properties of an object are not declared with the var keyword; they are
assigned directly to the object, differing from variable declarations.
112
Chapter 14: Basics of jQuery
1️. Should jQuery be Used?
• Simplifies JavaScript: jQuery is a fast, small, and feature-rich JavaScript library that
simplifies things like HTML document traversal and manipulation, event handling, and
animation. It makes it easier for developers to work with JavaScript.
• Powerful Effects and Animations: jQuery provides many built-in methods for creating
effects and animations, making it simple to add dynamic behavior to web pages without having
to code complex animations from scratch.
• Extensive Plugins: The jQuery community has developed a wide range of plugins that can
easily be integrated into projects, adding functionality like sliders, pop-ups, and more with
minimal effort.
• Easy DOM Manipulation: jQuery provides an intuitive syntax for selecting and
manipulating HTML elements, making tasks like changing text, adding classes, or modifying
attributes straightforward.
• Performance Overhead: jQuery can add extra weight to your project, which may impact
performance. For simple tasks, native JavaScript methods can be more efficient.
• Learning Curve: If you are new to JavaScript, learning jQuery might add unnecessary
complexity, as it introduces another layer of abstraction.
• Modern Alternatives: With advancements in JavaScript (like ES6 and beyond) and the rise
of frameworks like React, Vue, and Angular, many developers prefer using native JavaScript or
these modern frameworks instead of jQuery.
2️. Different Ways of Selecting Elements in HTML and Performing Actions on Them
Once elements are selected, various actions can be performed, such as:
• Adding/Removing Classes: Use methods to add or remove CSS classes for styling
changes.
• Adding Event Listeners: Attach events (like clicks or hovers) to perform actions when a
user interacts with an element.
jQuery Selectors:
o Example: $('ul > li') selects <li> elements that are direct children of <ul>.
o Example: $('h1, h2, h3') selects all <h1>, <h2>, and <h3> tags.
Using Selectors:
These selectors can be used in conjunction with jQuery methods to perform actions like changing
text, adding classes, or even chaining multiple actions together for a streamlined approach.
Definition:
jQuery event methods are functions that allow you to capture and respond to user interactions with
elements on a webpage, such as clicks, hovers, and keyboard inputs.
114
Implementing Event Methods:
2. Hover Event: Use .hover() to specify functions to run when an element is hovered over.
3. Key Event: Use .keydown() or .keyup() to trigger a function when a key is pressed or
released.
4. Form Events: Handle events like .submit() to perform actions when a form is submitted.
Summary:
Event methods make it easy to create interactive and responsive web pages by enabling developers to
specify what happens when users interact with different elements.
Overview:
The replaceChild() method is a DOM manipulation function that allows you to replace an existing child
node with a new node.
How It Works:
1. Select the Parent Node: First, select the parent element that contains the child you want to
replace.
2. Create the New Node: Use document.createElement() or similar methods to create a new
node.
3. Select the Child Node: Identify the child node you want to replace.
4. Replace the Child: Call the replaceChild() method, passing in the new node and the old node.
Example Concept:
Imagine you have a <div> that contains an old image and you want to replace it with a new one:
Implementation:
<div id="container">
115
<img id="oldImage" src="old.jpg" alt="Old Image" />
</div>
• JavaScript Logic:
o Use replaceChild() to replace the old image with the new one.
Summary:
Using replaceChild() allows you to dynamically change parts of the HTML DOM, providing a way to
update the content without removing the entire parent element.
1. The ______________ property returns the number of the internet host port (of the current
page).
A. window.location.port
Explanation: This property retrieves the port number used in the URL of the current page,
which is part of the window.location object.
5. Which of the following is/are the part/parts of the W3C DOM standard?
D. Core DOM, XML DOM, and HTML DOM
Explanation: The W3C DOM standard comprises three parts: Core DOM (which deals with the
general structure of documents), XML DOM (which specifically addresses XML documents),
and HTML DOM (which relates to HTML documents).
8. What among the following is appropriate when an event occurs when the user clicks on an
element?
A. onclick
Explanation: The onclick event handler is triggered when a user clicks on an element, making
it useful for interactive elements like buttons.
11. According to the W3C HTML DOM standard, everything in an HTML document is a ______.
NODE
Explanation: In the HTML DOM, every component of an HTML document (elements, attributes,
text, etc.) is represented as a node.
12. The _________ Constraint Validation HTML Input attribute specifies that the input field
requires an element.
required
Explanation: The required attribute indicates that a user must fill out the input field before
submitting the form.
13. The ________ HTML object property returns the domain name of the document server.
document.domain
Explanation: The document.domain property provides the domain name of the server that
hosts the current document.
14. The ________ JavaScript DOM method is used to create an HTML element.
document.createElement(element)
Explanation: This method creates a new HTML element specified by the element argument,
allowing dynamic manipulation of the document structure.
15. The __________ object lies at the top of the DOM hierarchy.
window object
Explanation: The window object is the root of the DOM hierarchy and serves as the global
object in web browsers, containing all global variables and functions.
117