MH State Board All Notes Free5th to 12th & BA, BSc, B.Com 🔍

HTML & JavaScript CBCCA4T04

RTMNU B.Com Semester 4 · Major: Computer Applications · 4 units · notes for every unit

UniversityRTMNU – Rashtrasant Tukadoji Maharaj Nagpur University, Nagpur
CourseB.Com (Four Year UG Programme, NEP 2020)
SemesterSemester IV
Paper codeCBCCA4T04
Paper titleHTML & JavaScript
CategoryMajor – Computer Applications
Credits4 credits (60 hours theory)
MarksTheory exam: 80 marks + 20 marks internal (CIE) = 100; minimum 40 to pass
Syllabusas per official RTMNU NEP 2020 B.Com syllabus (Direction No. 21 of 2024), session 2025-26

Unit topics below follow the official RTMNU syllabus. The practical paper CBCCA4P02 is separate. RTMNU official website · All RTMNU B.Com papers

Units

  1. 1Unit I: Introduction to HTML and CSS: Syntax, Selectors and InclusionNotes
  2. 2Unit II: CSS Measurement Units, Colours, Background, Fonts, Text and BordersNotes
  3. 3Unit III: JavaScript Basics: Scripts, DOM, Variables, Operators and Control StatementsNotes
  4. 4Unit IV: Functions, Objects, Arrays, DOM, Forms and EventsNotes

RTMNU B.Com Sem 4 · CBCCA4T04 · Unit I

Unit I: Introduction to HTML and CSS: Syntax, Selectors and Inclusion

Syllabus topics (RTMNU)

  • Introduction to HTML: Tags and Attributes
  • Basic HTML Syntax
  • CSS - Overview
  • Introduction
  • Advantages
  • Versions
  • Creation and maintenance of CSS
  • CSS Syntax
  • Type Selectors
  • Universal Selectors
  • Descendant Selectors
  • Class Selectors
  • ID Selectors
  • Child Selectors
  • Attribute Selectors
  • Multiple Style Rules
  • Grouping Selectors
  • CSS Inclusion - Embedded CSS - The <style> Element, Attributes
  • Inline CSS - The Style Attribute
  • External CSS - The <link> Element, Attributes
  • Imported CSS - @import Rule
  • CSS Rules Overriding
  • CSS Comments

Introduction to HTML: Tags and Attributes, Basic HTML Syntax

HTML (HyperText Markup Language) is the standard markup language used to create web pages. It tells the browser the structure of a page – headings, paragraphs, images, links, tables. It was created by Tim Berners-Lee (1991); the current version is HTML5.

  • Tag: a keyword inside angle brackets that marks an element, e.g. <p>. Most tags are in pairs – opening <b> and closing </b>. Some are empty (single) tags like <br>, <hr>, <img>.
  • Attribute: extra information about an element, written inside the opening tag as name="value", e.g. <img src="logo.png" width="100">. Common attributes: id, class, style, title, href, src, alt.
  • Element: opening tag + content + closing tag.
Basic HTML syntax
<!DOCTYPE html>
<html>
<head>
  <title>My Shop</title>
</head>
<body>
  <h1>Welcome</h1>
  <p>Best prices in Nagpur.</p>
</body>
</html>

<html> is the root, <head> holds the title and styles (not shown on page), <body> holds visible content.

CSS – Overview, Introduction and Advantages

CSS (Cascading Style Sheets) is a style sheet language used to describe the look of HTML elements – colours, fonts, spacing, borders and layout. HTML gives structure; CSS gives presentation. "Cascading" means that when many rules apply, they are combined in a fixed order of priority.

Advantages of CSS:

  1. Saves time – write a style once and use it on many pages.
  2. Easy maintenance – change one CSS file and the whole website changes.
  3. Pages load faster – less repeated code in HTML.
  4. Better styling – more options than plain HTML attributes.
  5. Multiple device support – different styles for mobile, desktop and print.
  6. Separation of content and design – HTML stays clean.

CSS Versions

VersionYearKey points
CSS11996First W3C recommendation: fonts, colours, text, margins
CSS21998Positioning, z-index, media types, more selectors
CSS2.12011 (final)Corrected and cleaned version of CSS2
CSS3From 1999 onwards (in modules)Divided into modules: rounded corners, shadows, gradients, animations, media queries

Creation and Maintenance of CSS

Steps: (1) plan the styles needed for the site; (2) write the rules in a text editor (Notepad, VS Code) and save with .css extension; (3) link the file to every HTML page; (4) to maintain, edit only the CSS file – all linked pages update. Group common styles and add comments so others can understand.

CSS Syntax

A CSS rule has a selector and a declaration block. Each declaration is a property: value; pair.

selector { property: value; }
h1 { color: blue; font-size: 24px; }

Here h1 is the selector, color and font-size are properties, blue and 24px are values.

CSS Selectors

A selector chooses which HTML elements a rule applies to.

SelectorSyntax exampleSelects
Type selectorp { color: red; }All <p> elements
Universal selector* { margin: 0; }Every element on the page
Descendant selectordiv p { ... }<p> anywhere inside a <div>
Class selector.price { ... }Elements with class="price" (can be used many times)
ID selector#header { ... }The one element with id="header" (unique)
Child selectorul > li { ... }<li> that are direct children of <ul>
Attribute selectorinput[type="text"] { ... }Elements having that attribute/value
Class selectorID selector
Written with a dot (.)Written with a hash (#)
Can be used on many elementsMust be unique on a page
Lower priorityHigher priority

Multiple Style Rules and Grouping Selectors

Multiple style rules: many properties can be given to one selector in one block: h1 { color: green; text-align: center; letter-spacing: 2px; }. Grouping selectors: when several selectors share the same style, separate them with commas: h1, h2, p { font-family: Arial; }. This reduces repeated code.

CSS Inclusion – Embedded CSS: the <style> Element and its Attributes

Embedded (internal) CSS is written inside the <style> element in the <head> section. It applies to that one page only. Attributes: type (text/css), media (screen, print, all).

<head>
<style type="text/css" media="all">
  body { background-color: #f0f0f0; }
</style>
</head>

Inline CSS – the style Attribute

Inline CSS is written directly in an element using the style attribute: <p style="color:red; font-size:18px;">Offer!</p>. It affects only that element and has the highest priority, but it mixes design with content and is hard to maintain.

External CSS is kept in a separate .css file and linked in the <head>: <link rel="stylesheet" type="text/css" href="style.css" media="all">. Attributes: rel (relation – stylesheet), href (path of the file), type (text/css), media (device). Best method for websites with many pages.

Imported CSS – @import Rule

The @import rule loads one style sheet into another. It must be written at the top of a style sheet or <style> block: @import url("colors.css"); It is useful to split big styles into smaller files, but it can slow loading slightly.

CSS Rules Overriding

When different rules apply to the same element, the browser decides by these rules:

  1. Inline style overrides internal and external styles.
  2. Internal and external styles: the rule written later wins.
  3. Specificity: ID selector > class/attribute selector > type selector.
  4. !important after a value overrides normal rules: color: red !important;

CSS Comments

Comments explain code and are ignored by the browser. In CSS they are written between /* and */, can be single or multi-line: /* Main heading style */. (HTML comments use <!-- -->.)

Exam tip: "Explain types of CSS" = embedded, inline, external and imported – give syntax of each and one line on when to use it. Always end with the priority order: inline > internal/external (later wins) > browser default.

Likely exam questions

  1. (Long, 8/16 marks) What is CSS? Explain its advantages and versions. Describe the syntax of a CSS rule with an example.
  2. (Long, 8/16 marks) Explain the different ways of including CSS in an HTML document: embedded, inline, external and imported CSS, with syntax. How are CSS rules overridden?
  3. (Short, 4 marks) Differentiate between class selector and ID selector.
  4. (Short, 4 marks) Explain universal, descendant and child selectors with examples.
  5. (Short, 4 marks) What are tags and attributes in HTML? Give examples.

RTMNU B.Com Sem 4 · CBCCA4T04 · Unit II

Unit II: CSS Measurement Units, Colours, Background, Fonts, Text and Borders

Syllabus topics (RTMNU)

  • CSS - Measurement Units
  • Colors - Hex Codes
  • Short Hex Codes
  • RGB Values
  • Building Color Codes
  • Browser Safe Colours
  • CSS - background
  • CSS fonts: Setting of Font Family, Style, Variant, Weight, Size, Size Adjust, Stretch, Shorthand Property
  • CSS Text - Setting of Text Colour, Direction, Indent, Alignment
  • Decorating the text: Setting of White Space Between Text
  • Text Cases
  • Text Shadow
  • CSS borders: Color Property, Style Property, Width Property
  • Border Properties Using Shorthand

CSS Measurement Units

Many CSS properties (width, font-size, margin) need a length value with a unit. There must be no space between the number and the unit (16px, not 16 px).

UnitTypeMeaning
pxAbsolutePixel – one dot on the screen; most common
ptAbsolutePoint = 1/72 inch; used in print
pcAbsolutePica = 12 points
in, cm, mmAbsoluteInch, centimetre, millimetre (real sizes, used for print)
%RelativePercentage of the parent element’s value
emRelativeRelative to the font size of the element (2em = twice the current font size)
remRelativeRelative to the font size of the root (html) element
exRelativeHeight of the small letter "x" of the font
vw, vhRelative1% of the browser window width / height

Relative units are preferred for responsive (mobile-friendly) design because they adjust automatically.

Colors: Hex Codes and Short Hex Codes

CSS colours can be given by name (red, navy), hex code, RGB value or other formats.

  • Hex code: a # followed by six hexadecimal digits (0–9, A–F) in the form #RRGGBB – two digits each for red, green and blue. Each pair ranges from 00 (none) to FF (full, = 255). Example: #FF0000 = red, #000000 = black, #FFFFFF = white.
  • Short hex code: a three-digit form #RGB used when each pair has the same two digits. The browser doubles each digit: #F00 = #FF0000, #0C9 = #00CC99.

RGB Values and Building Color Codes

RGB value: rgb(red, green, blue) with each value from 0 to 255 or as a percentage, e.g. rgb(255, 165, 0) = orange, rgb(0%, 0%, 100%) = blue. rgba() adds a fourth value for transparency (0 to 1).

Building colour codes: any colour is made by mixing red, green and blue light. Converting decimal to hex: 255 = FF, 128 = 80, 0 = 00. So rgb(255, 128, 0) becomes #FF8000. More of all three gives lighter colours; equal amounts give shades of grey (#808080).

ColourHexShort hexRGB
Black#000000#000rgb(0,0,0)
White#FFFFFF#FFFrgb(255,255,255)
Red#FF0000#F00rgb(255,0,0)
Green (lime)#00FF00#0F0rgb(0,255,0)
Blue#0000FF#00Frgb(0,0,255)
Yellow#FFFF00#FF0rgb(255,255,0)

Browser Safe Colours

Browser safe (web safe) colours are the 216 colours that looked the same on all browsers and operating systems on old 256-colour monitors. They use only the values 00, 33, 66, 99, CC and FF for each of red, green and blue (6 × 6 × 6 = 216), e.g. #3366CC, #FF9900. Modern screens show millions of colours, so this is mainly of historical importance.

CSS Background

PropertyUse / example
background-colorBackground colour: background-color: #f5f5dc;
background-imageImage as background: background-image: url("bg.jpg");
background-repeatrepeat, repeat-x, repeat-y, no-repeat
background-positionStarting position: center, top right, 50% 50%
background-attachmentscroll (moves with page) or fixed (stays in place)
background (shorthand)background: #fff url("logo.png") no-repeat center;

CSS Fonts: Family, Style, Variant, Weight, Size, Size Adjust, Stretch and Shorthand

PropertyValues / example
font-familyList of fonts in order of choice, ending with a generic family: font-family: "Times New Roman", Georgia, serif;
font-stylenormal, italic, oblique
font-variantnormal, small-caps (small letters shown as small capital letters)
font-weightnormal, bold, bolder, lighter, or 100 to 900 (400 = normal, 700 = bold)
font-sizepx, em, %, or keywords (small, medium, large, x-large): font-size: 18px;
font-size-adjustKeeps the x-height readable when a fallback font is used: font-size-adjust: 0.5; (limited browser support)
font-stretchMakes text narrower or wider: condensed, normal, expanded (works only if the font has such faces)
font (shorthand)Order: style variant weight size/line-height family: font: italic small-caps bold 16px/1.5 Arial, sans-serif;
Remember: In the font shorthand, font-size and font-family are compulsory and must come last, in that order.

CSS Text: Colour, Direction, Indent and Alignment

  • color – text colour: color: #333;
  • direction – writing direction: ltr (left to right, default) or rtl (right to left, for Urdu/Arabic).
  • text-indent – space before the first line of a paragraph: text-indent: 30px;
  • text-align – left, right, center, justify (both edges straight).

Decorating the Text, White Space, Text Cases and Text Shadow

  • text-decoration – none, underline, overline, line-through. Often used as a { text-decoration: none; } to remove the underline from links.
  • Space between text: letter-spacing (space between characters) and word-spacing (space between words): letter-spacing: 2px; word-spacing: 5px;
  • white-space – how spaces and line breaks are handled: normal (extra spaces joined), nowrap (no line wrap), pre (keeps spaces and line breaks as typed).
  • text-transform (text cases) – uppercase, lowercase, capitalize (first letter of each word capital), none.
  • text-shadow – shadow behind text: text-shadow: 2px 2px 4px gray; = horizontal offset, vertical offset, blur radius, colour.

CSS Borders: Color, Style, Width and Shorthand

PropertyValues / example
border-stylenone, solid, dotted, dashed, double, groove, ridge, inset, outset (must be set, otherwise no border shows)
border-widththin, medium, thick or a length: border-width: 3px;
border-colorAny colour: border-color: red;
Single sidesborder-top, border-right, border-bottom, border-left (e.g. border-bottom-color)
border (shorthand)width style colour: border: 2px solid #0066cc;

When four values are given (e.g. border-width: 1px 2px 3px 4px;) they apply clockwise: top, right, bottom, left.

Example combining Unit II properties
p.note {
  font: italic bold 16px Arial, sans-serif;
  color: #003366;
  text-align: justify;
  text-transform: capitalize;
  border: 2px dashed #F00;
  background-color: rgb(255, 255, 204);
}
Exam tip: For colour questions, explain hex, short hex and RGB with the same colour in all three forms (e.g. red = #FF0000 = #F00 = rgb(255,0,0)). Examiners like this one-line comparison.

Likely exam questions

  1. (Long, 8/16 marks) Explain the different ways of specifying colours in CSS: colour names, hex codes, short hex codes and RGB values. What are browser safe colours?
  2. (Long, 8/16 marks) Explain CSS font properties (font-family, font-style, font-variant, font-weight, font-size, font-size-adjust, font-stretch) and the font shorthand property with examples.
  3. (Short, 4 marks) Explain any four CSS measurement units.
  4. (Short, 4 marks) Explain CSS border properties with the shorthand property.
  5. (Short, 4 marks) Write short notes on text-transform and text-shadow.

RTMNU B.Com Sem 4 · CBCCA4T04 · Unit III

Unit III: JavaScript Basics: Scripts, DOM, Variables, Operators and Control Statements

Syllabus topics (RTMNU)

  • JavaScript - Introduction
  • Internal Vs. External Scripts
  • Internal JavaScript Code
  • Understand The JavaScript Language & The Document Object Model
  • Variable Declaration
  • Operators
  • Types of Operators: Arithmetic Operators, Assignment Operators, Comparison Operators, Logical Operators, Conditional Operators, Type Operators
  • Control Statements: Conditional Statement: if, if else, else if
  • Looping Statement: while, do while, for loop

JavaScript – Introduction

JavaScript (JS) is a lightweight, interpreted, client-side scripting language used to make web pages interactive – for example, checking a form before it is sent, showing alerts, changing content without reloading, image sliders. It was created by Brendan Eich at Netscape in 1995. Its standard is called ECMAScript. JavaScript is not the same as Java.

Features:

  1. Interpreted – runs directly in the browser; no compiling needed.
  2. Client-side – runs on the user’s computer, so it reduces load on the server.
  3. Event-driven – reacts to clicks, key presses, page load.
  4. Dynamically typed – the type of a variable is decided by its value.
  5. Object-based – uses objects like document, window, Date, Math.
  6. Case-sensitive – total and Total are different.

Internal vs External Scripts and Internal JavaScript Code

Internal script: JavaScript code written between <script> and </script> tags inside the HTML page, in <head> or <body>.

Internal JavaScript code
<body>
<script>
  document.write("Welcome to PadhaiNotes");
</script>
</body>

External script: code saved in a separate file with .js extension and linked with the src attribute: <script src="main.js"></script>. The external file has no <script> tags inside it.

Internal scriptExternal script
Written inside the HTML pageWritten in a separate .js file
Used for one page onlySame file can be used by many pages
HTML and JS are mixedHTML and JS are separate, cleaner code
No extra file to downloadBrowser can cache the file, so pages load faster later
Good for small codeGood for large websites

Understand the JavaScript Language and the Document Object Model

A JavaScript program is a set of statements, usually ended with a semicolon. Comments are written as // single line or /* multi-line */. Output can be shown with document.write(), alert() (pop-up box), console.log() (browser console) or by changing an element’s innerHTML.

Document Object Model (DOM): when a page loads, the browser builds a tree of objects from the HTML. The document object is the root; every tag becomes a node (element) in this tree. JavaScript uses the DOM to read and change the page: document.getElementById("total").innerHTML = "₹500"; changes the text of the element having id="total". Common DOM methods: getElementById(), getElementsByTagName(), getElementsByClassName(), querySelector().

Variable Declaration

A variable is a named container for storing data. JavaScript declares variables with three keywords:

KeywordScopeCan be re-assigned?Notes
varFunction scopeYesOld way; can be declared again
letBlock scope { }YesModern way (ES6, 2015)
constBlock scope { }NoFor fixed values; must be given a value when declared

Example: var name = "Asha"; let qty = 5; const GST = 18; Naming rules: start with a letter, _ or $; no spaces; not a reserved word; case-sensitive. Data types: number, string, boolean, undefined, null, object, plus bigint and symbol.

Operators and Types of Operators

An operator is a symbol that performs an operation on values (operands).

TypeOperatorsExample (a = 10, b = 3)
Arithmetic+ - * / % ** ++ --a/b = 3.333…, a%b = 1, a**2 = 100
Assignment= += -= *= /= %=x = 10; x += 5 gives 15
Comparison== === != !== > < >= <=5 == "5" is true; 5 === "5" is false
Logical&& || !true && false is false; !true is false
Conditional (ternary)condition ? value1 : value2(72 >= 40) ? "Pass" : "Fail" gives "Pass"
Typetypeof, instanceoftypeof 42 is "number"; d instanceof Date is true
  • == vs ===: == compares only values after converting types; === (strict equality) compares value and type.
  • + with strings: "5" + 2 gives "52" (joining), but "5" - 2 gives 3.
  • typeof returns the type as a string: "number", "string", "boolean", "undefined", "object", "function". (typeof null gives "object" – a known quirk.)

Control Statements – Conditional Statements: if, if else, else if

Conditional statements run code only when a condition is true.

if, else if, else ladder
let marks = 72;
if (marks >= 75) {
  document.write("Distinction");
} else if (marks >= 60) {
  document.write("First Class");
} else if (marks >= 40) {
  document.write("Pass");
} else {
  document.write("Fail");
}

Output: First Class. if alone runs a block when true; if…else chooses between two blocks; else if checks many conditions in order and runs the first true one.

Looping Statements: while, do while, for loop

  • while – checks the condition first, then runs the body (entry controlled). let i = 1, s = 0; while (i <= 5) { s += i; i++; } gives s = 15.
  • do…while – runs the body once first and checks the condition at the end (exit controlled), so it runs at least once. let j = 10; do { j++; } while (j < 5); gives j = 11.
  • for – initialisation, condition and update in one line; used when the count is known.
for loop: first five even numbers
for (let k = 1; k <= 5; k++) {
  document.write(k * 2 + " ");
}

Output: 2 4 6 8 10. break stops a loop and continue skips to the next round.

Exam tip: In "internal vs external script" give the syntax of both and a 5-point difference table. In operator questions, always explain == vs === with the example 5 == "5" (true) and 5 === "5" (false).

Likely exam questions

  1. (Long, 8/16 marks) What is JavaScript? Explain its features. Differentiate between internal and external scripts with examples.
  2. (Long, 8/16 marks) Explain the types of operators in JavaScript (arithmetic, assignment, comparison, logical, conditional and type operators) with examples.
  3. (Short, 4 marks) What is the Document Object Model (DOM)?
  4. (Short, 4 marks) Differentiate between var, let and const.
  5. (Short, 4 marks) Explain the do...while loop in JavaScript with an example.

RTMNU B.Com Sem 4 · CBCCA4T04 · Unit IV

Unit IV: Functions, Objects, Arrays, DOM, Forms and Events

Syllabus topics (RTMNU)

  • Function: Function Declaration
  • built in Functions
  • Standard Date and Time Functions
  • HTML Document Object Model
  • working with HTML Form and Its Elements
  • Passing Parameter to Function
  • Returning A Value from Function
  • Array
  • Object: Creating Object
  • Accessing Object Properties
  • Array Object
  • String Object
  • Date Object
  • Math Object
  • Window Object
  • Navigator Object
  • Events: Event Type: Mouse Events
  • Frame/Object Events
  • Form Events

Function: Function Declaration

Definition: A function is a named block of code that does a particular task and runs only when it is called. It allows code reuse and makes programs modular.

Syntax
function greet() { // declaration
  alert("Welcome!");
}
greet(); // call

A function is declared with the keyword function, a name, brackets for parameters and a body in { }. Functions can also be stored in variables (function expressions) or written as arrow functions: const sq = x => x * x;

Passing Parameter to Function and Returning a Value from Function

Parameters are names listed in the function definition; arguments are the actual values passed in the call. The return statement sends a value back to the caller and ends the function.

function amountWithGST(price, rate) {
  return price + price * rate / 100;
}
let total = amountWithGST(1000, 18); // 1180
document.write("Total = ₹" + total);

Built-in Functions

FunctionUseExample → result
alert(msg)Shows a message boxalert("Saved")
prompt(msg)Input box; returns the typed textprompt("Your name?")
confirm(msg)OK/Cancel box; returns true/falseconfirm("Delete?")
parseInt(s)Converts string to integerparseInt("25.7") → 25
parseFloat(s)Converts string to decimal numberparseFloat("25.7") → 25.7
isNaN(x)Checks "Not a Number"isNaN("abc") → true
Number(x) / String(x)Type conversionNumber("12") → 12
eval(s)Evaluates a string as code (avoid for safety)eval("2+3*4") → 14
setTimeout(f, ms)Runs f once after a delaysetTimeout(show, 2000)

Standard Date and Time Functions – Date Object

The Date object handles dates and times. Create it with let d = new Date(); (current date and time) or new Date(2025, 0, 26) (months start from 0, so 0 = January).

MethodReturns
getFullYear()Year, e.g. 2025
getMonth()Month 0–11
getDate()Day of month 1–31
getDay()Day of week 0–6 (0 = Sunday)
getHours(), getMinutes(), getSeconds()Time parts
setFullYear(), setMonth(), setDate()Change date parts
toDateString(), toLocaleDateString()Readable date text

Example: for new Date(2025, 0, 26), getDay() returns 0 because 26 January 2025 was a Sunday.

HTML Document Object Model and Working with HTML Form and its Elements

The HTML DOM is the tree of objects that the browser builds from a page. With it, JavaScript can find elements (getElementById, getElementsByTagName, querySelector), change their content (innerHTML), style (element.style.color) and attributes, and add or remove elements.

Forms: a <form> collects user input through elements like text box, password, radio button, checkbox, select (drop-down), textarea and buttons. JavaScript reads them through .value (text), .checked (radio/checkbox) and selectedIndex (list), and is used mainly for form validation – checking data before sending it to the server.

Form validation example
<form name="f1" onsubmit="return check()">
  Mobile: <input type="text" id="mob">
  <input type="submit" value="Send">
</form>
<script>
function check() {
  let m = document.getElementById("mob").value;
  if (m.length != 10 || isNaN(m)) {
    alert("Enter a 10-digit mobile number");
    return false; // stops submission
  }
  return true;
}
</script>

Array and Array Object

An array stores many values in one variable: let fees = [30, 10, 20]; or new Array(30, 10, 20). Index starts at 0; fees[0] is 30. A JS array can hold mixed types and grows automatically.

Property / methodUse (fees = [30,10,20])
lengthNumber of elements → 3
push(x) / pop()Add at end / remove last
unshift(x) / shift()Add at start / remove first
join("-")Joins into a string → "30-10-20"
sort() / reverse()Arrange / reverse order (for numbers use sort((a,b)=>a-b))
indexOf(x)Position of x, or -1 if not found
concat(), slice()Join arrays / copy a part

Object: Creating Object and Accessing Object Properties

An object is a collection of related data (properties) and functions (methods) as name:value pairs. Ways to create: (1) object literal, (2) new Object(), (3) constructor function.

let student = {
  name: "Asha",
  roll: 12,
  show: function() { return this.name + " " + this.roll; }
};
document.write(student.name); // dot notation: Asha
document.write(student["roll"]); // bracket notation: 12
document.write(student.show()); // method: Asha 12

String Object and Math Object

String methodExample (s = "Nagpur University") → result
length17
toUpperCase() / toLowerCase()"NAGPUR UNIVERSITY"
charAt(i)charAt(0) → "N"
indexOf(t)indexOf("Uni") → 7
substring(a, b)substring(0, 6) → "Nagpur"
replace(a, b)replace("Nagpur", "RTMNU") → "RTMNU University"
split(" ")["Nagpur", "University"]
Math methodResult
Math.round(4.6)5
Math.ceil(4.1) / Math.floor(4.9)5 / 4
Math.sqrt(64)8
Math.pow(2, 3)8
Math.max(3, 9, 1) / Math.min(3, 9, 1)9 / 1
Math.abs(-7)7
Math.random()Random number from 0 up to (not including) 1
Math.PI3.14159…

Window Object and Navigator Object

  • Window object – the top object; it represents the browser window. All global variables and functions belong to it. Methods: alert(), prompt(), confirm(), open() (new window), close(), setTimeout(), setInterval(), print(). Properties: innerWidth, innerHeight, location, history, document.
  • Navigator object – gives information about the browser: navigator.userAgent (browser details), navigator.language (e.g. "en-IN"), navigator.onLine (true if connected), navigator.cookieEnabled, navigator.platform.

Events: Event Type – Mouse Events, Frame/Object Events, Form Events

An event is an action that happens in the browser, such as a click or page load. An event handler is the code that runs in response: <button onclick="greet()">Hi</button> or element.addEventListener("click", greet);

Event typeEventsWhen it happens
Mouse eventsonclick, ondblclick, onmousedown, onmouseup, onmouseover, onmouseout, onmousemoveClick, double-click, pointer enters/leaves/moves over an element
Frame/Object eventsonload, onunload, onresize, onscroll, onerror, onabortPage or image finishes loading, page is left, window resized or scrolled, error while loading
Form eventsonsubmit, onreset, onchange, onfocus, onblur, onselect, oninputForm submitted or reset, value changed, field gets or loses focus, text selected or typed
Exam tip: For "events", draw the three-column table (event type, events, when it happens) and add one example like <body onload="..."> or <input onblur="...">. For objects, list at least four methods each of String, Math and Date with outputs.

Likely exam questions

  1. (Long, 8/16 marks) What is a function in JavaScript? Explain function declaration, passing parameters and returning a value with examples. List any six built-in functions.
  2. (Long, 8/16 marks) What is an event? Explain mouse events, frame/object events and form events with examples. Write a JavaScript code to validate a form field.
  3. (Short, 4 marks) Explain any four methods each of the String object and the Math object.
  4. (Short, 4 marks) How is an object created in JavaScript? How are its properties accessed?
  5. (Short, 4 marks) Write short notes on the Window object and the Navigator object.