0% found this document useful (0 votes)
7 views4 pages

Web Assignment

JavaScript is a high-level programming language essential for web development, enabling dynamic content and client-side execution. It includes variable declarations using 'var', 'let', and 'const', each with different scopes and constraints. Additionally, form validation is crucial for security, data quality, and user experience, while website hosting provides the necessary resources for making websites accessible online.

Uploaded by

kanishkgoyal336
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Web Assignment

JavaScript is a high-level programming language essential for web development, enabling dynamic content and client-side execution. It includes variable declarations using 'var', 'let', and 'const', each with different scopes and constraints. Additionally, form validation is crucial for security, data quality, and user experience, while website hosting provides the necessary resources for making websites accessible online.

Uploaded by

kanishkgoyal336
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

JavaScript: De nition and Importance


De nition:

JavaScript (JS) is a high-level, interpreted, and multi-paradigm programming language.


Originally designed to make web pages "live," it is now a cornerstone of modern software
development. It follows the ECMAScript standard and is characterised by being
prototype-based, single-threaded, and event-driven.

Importance in Web Development:

• The Third Pillar: Along with HTML (Structure) and CSS (Presentation), JS provides
the Behaviour. Without it, the web would be static and unresponsive.

• Client-Side Execution: JS runs directly in the user's browser. This reduces server
load and allows for instantaneous feedback (e.g., character counts in text areas).

• Dynamic Content Manipulation: Through the Document Object Model (DOM),


JS can change text, styles, and attributes on a page without a reload.

• Asynchronous Communication (AJAX/Fetch): JS allows websites to update data


in the background. For example, scrolling through a social media feed where new
posts appear automatically.

• Universal Reach: It is the only language that runs natively in all modern browsers.
With environments like [Link] , it has moved to the server-side, making "Full-
Stack JavaScript" a reality.

2. JavaScript Variables and Examples


Variables are used to store data that can be referenced and manipulated in a program. In
modern JavaScript (ES6+), there are three ways to declare them:

A. var (The Legacy Way)

• Scope: Function-scoped. It is not limited to the block {} it is de ned in.

• Hoisting: It is hoisted to the top of its scope and initialised as unde ned.

• Example: ```javascript
var city = "Chandigarh";
var city = "Delhi"; // Redeclaration is allowed (often leads to bugs)

B. let (The Modern Standard)

• Scope: Block-scoped. It only exists within the {} where it is declared.


fi
fi
fi
fi
• Hoisting: It is hoisted but remains in a "Temporal Dead Zone," meaning you cannot
use it before declaration.

• Example:
JavaScript

let score = 90;

• score = 95; // Reassignment is allowed


C. const (For Constants)

• Scope: Block-scoped.

• Constraint: Must be initialised during declaration and cannot be reassigned.

• Example:
JavaScript

const PI = 3.14159;

• // PI = 4; // Error: Assignment to constant variable.


3. Form Validation: Purpose and Necessity


What is Form Validation?

It is the process of ensuring that the input provided by the user in a web form meets the
required criteria (format, length, type) before it is processed or sent to a server.

Why is it Required?

1. Security (Crucial): It acts as the rst line of defence against attacks like Cross-
Site Scripting (XSS) and SQL Injection by ltering out malicious characters.

2. Data Quality: It ensures the database remains clean. For instance, preventing a
user from entering text in a "Phone Number" eld.

3. User Experience (UX): It provides real-time guidance. Instead of waiting for a page
reload to nd out a password was too short, the user gets an immediate alert.

4. Reduced Server Load: By catching errors on the client side (browser), you save
the server from processing invalid requests, which saves bandwidth and processing
power.
fi
fi
fi
fi
4. JavaScript Program for Login Validation
For a 10-mark answer, provide a clean, commented script that handles the logic effectively.

JavaScript

// Function to validate the login form


function validateLogin() {
// 1. Fetching input values from the DOM
const email = [Link]("email").value;
const password = [Link]("password").value;
const errorMessage = [Link]("error-box");

// 2. Logic: Check for empty elds


if (email === "" || password === "") {
[Link] = "Error: All elds are required.";
return false; // Prevent form submission
}

// 3. Logic: Check for valid email format using Regex


const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (![Link](email)) {
[Link] = "Error: Please enter a valid email address.";
return false;
}

// 4. Logic: Password length constraint


if ([Link] < 8) {
[Link] = "Error: Password must be at least 8 characters.";
return false;
}

// If all checks pass


alert("Login Successful!");
return true;
}

5. Website Hosting and Its Working

De nition:
Website hosting is a service that provides the storage space and resources (CPU, RAM)
on a specialised computer called a Server that is connected to the internet 24/7. This
allows your website to be accessible to anyone in the world.

How it Works (Step-by-Step):

1. Uploading Files: A developer uploads the website les (HTML, JS, Images) to the
host's server via FTP (File Transfer Protocol) or a control panel.
fi
fi
fi
fi
2. Domain Name System (DNS): When you buy a domain (e.g., [Link]), you
point it to the IP Address of your hosting server.

3. The Request: A user enters your URL in their browser. The browser contacts the
DNS to nd the server's IP.

4. Processing: The server receives the request, nds the speci c les requested, and
processes any server-side code (like [Link] or PHP).

5. The Response: The server sends the data back to the user's browser, which
assembles the code into the visual webpage you see.
fi
fi
fi
fi

You might also like