Understanding Markup, Styling, and Scripting Languages
Understanding Markup, Styling, and Scripting Languages
1. Markup Language:
A markup language is used to structure and describe the content of a web page or document.
It does not perform any logic or calculation — it only defines what elements are present and
how they are organized.
Purpose:
Example:
2. Styling Language
A styling language (or style sheet language) is used to control the appearance and layout of a
structured document (like HTML).
It changes how things look, not what they mean.
Purpose:
To design or style the web page — color, size, spacing, fonts, etc.
Example:
Purpose:
Example:
JavaScript
Summary Table
Example
Type Purpose Example Usage
Language
Scripting Languages
Unlike traditional programming languages (like C or Java), scripting languages are interpreted
(not compiled).
Client-side scripting languages run inside the web browser (on the user’s device).
They are mainly used for user interaction, form validation, animations, and dynamic content.
Common Languages:
JavaScript
VBScript (now outdated)
Server-side scripting runs on the web server before the page is sent to the user’s browser.
It’s mainly used for database connectivity, form handling, user authentication, etc.
Common Languages:
PHP
Python (with Django/Flask)
[Link] (JavaScript on server)
ASP (Active Server Pages)
Ruby on Rails
Introduction to JavaScript
Definition:
JavaScript is a scripting language used to make web pages interactive, dynamic, and user-
friendly. It runs directly in the web browser and allows developers to control web page
behavior. It is often called the “language of the web” because almost every modern website
uses JavaScript.
History of JavaScript
Year Event
1995 Renamed to LiveScript, and then finally to JavaScript for marketing reasons (to ride
(Later) on Java’s popularity).
1996 Microsoft created a similar language called JScript for Internet Explorer.
1999 – Multiple ECMAScript versions were released to improve functionality and browser
2009 support.
ECMAScript 6 (ES6) was released — a major update with new features like let,
2015
const, arrow functions, and classes.
JavaScript is a core technology of the web, alongside HTML and CSS, and is used
Today
everywhere — from websites to mobile apps and even IoT devices.
Full Form of ECMAScript
Example:
JavaScript version ES6 means ECMAScript 2015, which introduced modern features.
Advantages of JavaScript
Inline JavaScript
In this method, JavaScript code is written directly inside an HTML tag using an event handler
attribute, such as onclick, onmouseover, onchange, etc.
Syntax:
Example:
<html>
<head>
<title>Inline JavaScript Example</title>
</head>
<body>
<h2>Inline JavaScript Example</h2>
<button This is Inline JavaScript.')">Click Me</button>
</body>
</html>
Internal JavaScript
Internal JavaScript is written inside <script> tags in the same HTML file.
It is placed either in the <head> or <body> section.
Syntax:
<script>
// JavaScript code here
</script>
<html>
<head>
<title>Internal JavaScript Example</title>
<script>
function msg()
{
alert("Welcome to Internal JavaScript!");
}
</script>
</head>
<body>
<h2>Click the Button Below</h2>
<button Me</button>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Internal Script in Body</title>
</head>
<body>
<script>
function msg()
{
alert("Welcome to Internal JavaScript!");
}
</script>
<h2>Click the Button Below</h2>
<button Me</button>
</body>
</html>
External JavaScript
External JavaScript means writing your script code in a separate .js file and linking it to your
HTML file using the <script src=""> tag.
This method is best for large projects or when the same script is used on multiple pages.
Syntax:
<script src="[Link]"></script>
Step-by-Step Example:
In JavaScript, data types define the type of value a variable can hold. JavaScript is a
dynamically typed language, which means you don’t need to declare the data type of a
variable — it is determined automatically at runtime based on the value assigned.
These are the basic and immutable types. There are 6 primitive data types:
(a) Number
Example:
(b) String
Represents a sequence of characters enclosed in single (' '), double (" "), or backticks ( ).
Example:
(c) Boolean
Example:
(d) Undefined
Example:
let x;
[Link](x); // Output: undefined
[Link] (typeof x); // Output: undefined
(e) Null
Example:
Used for very large numbers beyond the safe integer limit of Number.
Example:
(a) Object
Example:
let student = {
name: "Pramod",
age: 20,
isPassed: true
};
[Link]([Link]); // Output: Pramod
(b) Array
(c) Function
Example:
function msg()
{
return "Hello World!";
}
[Link](msg()); // Output: Hello World!
Variables in JavaScript
A variable in JavaScript is a container (storage location) used to store data or values that can
be used and modified later in the program. You can think of it like a box with a name that holds
some information.
Syntax
keyword variableName = value;
1. Variable names must start with a letter, underscore (_) or dollar sign ($)
Example:
Valid:
1name, @data
1. var Keyword
Example:
2. let Keyword
{
let city = "Delhi";
[Link](city); // Output: Delhi
}
[Link](city); // Error: city is not defined
3. const Keyword
Introduced in ES6
Block-scoped
Cannot be redeclared or updated
Must be initialized at the time of declaration
Example:
// Not allowed
// country = "USA"; // Error
// const country; // Error: must initialize
Operator in JavaScript
An operator is a special symbol that tells the JavaScript engine to perform a specific
operation on one or more values (called operands).
Every operator performs a particular kind of task like addition, comparison, assignment, or
logical testing. The values (numbers, strings, variables, etc.) that operators work on are called
operands.
let a = 10;
let b = 5;
let result = a + b;
Here:
+ is the operator
a and b are operands
It performs addition operation
Output: 15
let a = 5;
a++; // increment by 1
Here:
Here:
1. Arithmetic Operators
+ Addition 10 + 5 15
- Subtraction 10 - 5 5
* Multiplication 10 * 5 50
/ Division 10 / 5 2
% Modulus (Remainder) 10 % 3 1
** Exponentiation 2 ** 3 8
Example:
let a = 10, b = 3;
[Link](a + b); // 13
[Link](a - b); // 7
[Link](a * b); // 30
[Link](a / b); // 3.3333
[Link](a % b); // 1
[Link](a ** b); // 1000
2. Assignment Operators
= x = 10 Assigns value 10 to x
+= x += 5 x=x+5
-= x -= 3 x=x-3
*= x *= 2 x=x*2
/= x /= 4 x=x/4
%= x %= 3 x=x%3
**= x **= 2 x = x ** 2
Example:
let x = 10;
x += 5; // x = 15
x *= 2; // x = 30
[Link](x); // Output: 30
Example:
let a = 5, b = "5";
[Link] (a == b); // true
[Link] (a === b); // false
[Link] (a != b); // false
[Link] (a !== b); // true
4. Logical Operators
&& AND True if both conditions are true (5 > 2 && 10 > 5) true
Example:
~ NOT ~5 -(5+1) → -6
Example:
6. String Operators
Example:
let firstName = "Pramod";
let lastName = "Kumar";
let fullName = firstName + " " + lastName;
[Link](fullName); // Output: Pramod Kumar
Syntax:
Example:
🔹 8. Type Operators
Operator Description Example Output
Example:
prompt() function:
The prompt() function displays a dialog box that asks the user to input some text. It is mostly
used in browser-based JavaScript programs.
<html>
<body>
<script>
let name = prompt("Enter your name:");
[Link]("Hello " + name + "! Welcome to JavaScript.");
</script>
</body>
</html>
<html>
<body>
<script>
let num1 = prompt("Enter first number:");
let num2 = prompt("Enter second number:");
Conditional statements in JavaScript are used to perform different actions based on different
conditions.
They allow the program to make decisions depending on whether a condition is true or false.
1. if statement
2. if...else statement
3. if...else if...else ladder
4. switch statement
5. Ternary operator (? :)
1. if Statement
Syntax:
if (condition)
{
// code to be executed if condition is true
}
Example:
<script>
let age = 18;
Output:
2. if...else Statement
The if...else statement executes one block of code if the condition is true, and another block if
the condition is false.
Syntax:
if (condition)
{
// code if condition is true
}
else
{
// code if condition is false
}
Example:
<script>
let marks = 40;
Output:
This structure is used when you have multiple conditions to check one after another.
Syntax:
if (condition1)
{
// code if condition1 is true
}
else if (condition2)
{
// code if condition2 is true
}
else
{
// code if all conditions are false
}
Example:
<script>
let percentage = 85;
Output:
Grade: A
4. switch Statement
The switch statement is used to perform different actions based on different values of a
variable.
Syntax:
switch(expression)
{
case value1:
// code block
break;
case value2:
// code block
break;
default:
// code block
}
Example:
<script>
let day = 3;
let dayName;
switch (day)
{
case 1:
dayName = "Sunday";
break;
case 2:
dayName = "Monday";
break;
case 3:
dayName = "Tuesday";
break;
case 4:
dayName = "Wednesday";
break;
case 5:
dayName = "Thursday";
break;
case 6:
dayName = "Friday";
break;
case 7:
dayName = "Saturday";
break;
default:
dayName = "Invalid day";
}
Output:
Today is Wednesday
5. Ternary Operator ( ? : )
The ternary operator is a shortcut for the if...else statement. It takes three operands: condition,
value if true, and value if false.
Syntax:
Example:
<script>
let age = 20;
let result = (age >= 18) ? "Adult" : "Minor";
[Link](result);
</script>
Output:
Adult
Looping Statement
A loop is a control structure that allows you to execute a block of code repeatedly as long as a
specified condition is true. It helps reduce code repetition and makes programs shorter and more
efficient.
1. for loop
2. while loop
3. do...while loop
4. for...in loop
5. for...of loop
1. for Loop
The for loop is used when you know in advance how many times you want to execute a
statement or block of statements.
Syntax:
<script>
for (let i = 1; i <= 5; i++)
{
[Link](i + "<br>");
}
</script>
Output:
1
2
3
4
5
<script>
let sum = 0;
for (let i = 1; i <= 5; i++)
{
sum = sum + i;
}
[Link]("Sum = " + sum);
</script>
Output:
Sum = 15
2. while Loop
The while loop executes a block of code as long as the specified condition is true.
Syntax:
while (condition)
{
// code to be executed
}
Example:
<script>
let i = 1;
while (i <= 5)
{
[Link](i + "<br>");
i++;
}
</script>
Output:
1
2
3
4
5
3. do...while Loop
The do...while loop is similar to the while loop, except it executes the code block at least once,
even if the condition is false.
Syntax:
do
{
// code to be executed
} while (condition);
Example:
<script>
let i = 1;
do
{
[Link](i + "<br>");
i++;
} while (i <= 5);
</script>
Output:
1
2
3
4
5
Note: The condition is checked after executing the code block once.
4. for...in Loop
The for...in loop is used to iterate over the properties (keys) of an object.
Syntax:
Example:
<script>
let person = {name: "Pramod", age: 25, city: "Delhi"};
Output:
name : Pramod
age : 25
city : Delhi
5. for...of Loop
The for...of loop is used to iterate over iterable objects such as arrays, strings, or sets.
Syntax:
<script>
let fruits = ["Apple", "Banana", "Mango"];
Output:
Apple
Banana
Mango
<script>
let name = "RAM";
Output:
R
A
M
JavaScript Popup Boxes are built-in browser dialog boxes used to interact with users — such
as displaying messages, asking for confirmation, or taking input.
They are simple pop-up windows that appear in front of the web page.
Types of JavaScript Popup Boxes
1. alert() box
2. confirm() box
3. prompt() box
1. alert() Box
Syntax:
alert("message");
<html>
<body>
<script>
alert("Welcome to JavaScript!");
</script>
</body>
</html>
Explanation:
<!DOCTYPE html>
<html>
<body>
<button Me</button>
<script>
function showAlert()
{
alert("Button was clicked!");
}
</script>
</body>
</html>
Explanation:
When the user clicks the button, the message box appears.
2. confirm() Box
The confirm() box is used to ask the user for confirmation — typically for Yes/No or
OK/Cancel type questions.
It returns:
Syntax:
confirm("message");
<!DOCTYPE html>
<html>
<body>
<script>
let result = confirm("Do you want to continue?");
if (result)
{
[Link]("You pressed OK!");
}
else
{
[Link]("You pressed Cancel!");
}
</script>
</body>
</html>
or
<!DOCTYPE html>
<html>
<body>
<button Data</button>
<script>
function deleteData()
{
let confirmDelete = confirm("Are you sure you want to delete this data?");
if (confirmDelete)
{
alert("Data deleted successfully!");
}
else
{
alert("Delete action canceled.");
}
}
</script>
</body>
</html>
Explanation:
3. prompt() Box
Syntax:
<html>
<body>
<script>
let name = prompt("Enter your name:");
[Link]("Hello, " + name + "!");
</script>
</body>
</html>
Output:
Hello, Pramod!
<html>
<body>
<script>
let a = prompt("Enter first number:");
let b = prompt("Enter second number:");
let sum = parseInt(a) + parseInt(b);
alert("The sum is: " + sum);
</script>
</body>
</html>
Explanation:
Array in JavaScript
An Array in JavaScript is a special type of variable that can store multiple values in a single
variable name, instead of creating separate variables for each value.
Arrays are ordered collections of elements, which can be numbers, strings, objects, or even
other arrays.
Syntax of Array
let array_name = [value1, value2, value3, ...];
Example:
Here:
fruits is an array.
It contains 3 elements → "Apple", "Banana", "Mango".
You can access elements using their index number (starting from 0).
Output:
Number of fruits: 3
<script>
let fruits = ["Apple", "Banana", "Mango", "Orange"];
Output:
Apple
Banana
Mango
Orange
<script>
let fruits = ["Apple", "Banana", "Mango"];
An event in JavaScript is an action or occurrence that happens in the browser, which the
program can respond to.
JavaScript allows you to “listen” for these events and then execute code (called an event
handler) when they occur.
<!DOCTYPE html>
<html>
<body>
</body>
</html>
You can assign an event handler to an HTML element inside a <script> tag.
<!DOCTYPE html>
<html>
<body>
<script>
[Link]("myBtn"). >{
alert("Button clicked using DOM event handling!");
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h2>addEventListener() Example</h2>
<button id="btn">Click Me</button>
<script>
[Link]("btn").addEventListener("click", function()
{
alert("Hello! You used addEventListener()");
});
</script>
</body>
</html>
JavaScript Objects
Syntax:
let objectName = {
key1: value1,
key2: value2,
key3: value3
};
Example:
let student = {
name: "Aarav",
age: 20,
course: "BCA",
isPassed: true
};
Here:
[Link](student["age"]); // Output: 20
Deleting a Property
delete [Link];
JavaScript Functions
Syntax:
function msg()
{
alert("Welcome to JavaScript!");
}
function add(a, b)
{
return a + b;
}
function multiply(x, y)
{
let result = x * y;
return result;
}
Form Validation means checking whether the user has filled in all fields correctly before the
form is submitted.
It ensures:
Client-side validation Done in the browser using JavaScript before sending data to the server
Usually, we perform client-side validation using JavaScript to save time and improve user
experience.
if (name == "")
{
alert("Name must be filled out!");
return false; // prevent form submission
}
return true; // allow form submission
}
</script>
</head>
<body>
<h2>Simple Form Validation</h2>
</body>
</html>
if ()
{
alert("Please enter a valid email address!");
return false;
}
return true;
}
</script>
</head>
<body>
<h2>Email Validation Example</h2>
</body>
</html>
if (name == "") {
alert("Please enter your name!");
return false;
}
if () {
alert("Please enter a valid email!");
return false;
}
if ([Link] < 6) {
alert("Password must be at least 6 characters long!");
return false;
}
<body>
<h2>Form Validation Example</h2>
<form name="myForm" validateForm()">
Name: <input type="text" name="name"><br><br>
Email: <input type="text" name="email"><br><br>
Password: <input type="password" name="password"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
if () {
alert("Please enter a valid 10-digit phone number!");
return false;
}
return true;
}
</script>
</head>
<body>
<h2>Phone Number Validation</h2>
</body>
</html>
<body>
<h2>Password Validation</h2>
</body>
</html>