[Go to site: main page, start]

0% found this document useful (0 votes)
4 views3 pages

Internet Programming Assignment Notes

The document contains notes on various internet programming concepts, including variable scope with 'var' and 'let', array manipulation using filter and map methods, the benefits of event delegation in handling clicks, the use of event.preventDefault() in form validation, and the differences between JavaScript objects and JSON. Key examples illustrate how these concepts are applied in practical scenarios. The notes serve as a quick reference for understanding these fundamental programming principles.

Uploaded by

nyalemgeta
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)
4 views3 pages

Internet Programming Assignment Notes

The document contains notes on various internet programming concepts, including variable scope with 'var' and 'let', array manipulation using filter and map methods, the benefits of event delegation in handling clicks, the use of event.preventDefault() in form validation, and the differences between JavaScript objects and JSON. Key examples illustrate how these concepts are applied in practical scenarios. The notes serve as a quick reference for understanding these fundamental programming principles.

Uploaded by

nyalemgeta
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

Internet Programming Assignment Notes

Name-Nebiyu Yalemgeta
Section-c
Id:1116/16

Q1. Output of score and age in Console


if (true) {
var score = 10;
let age = 20;}
[Link](score); // [Link](age); // Error: age is not
defined

var is function-scoped, meaning it can be accessed outside the block where


it’s declared.

let is block-scoped, so it only works inside the {} block. That’s why score
prints 10, but age gives an error—it’s not visible outside the if block.

Q2. Working with prices Array


let prices = [100, 50, 200, 30];

1. Filter prices above 60:

let filtered = [Link](p => p > 60);[Link](filtered); //


[100, 200]

filter() checks each item and keeps only those that match the condition.

2. Apply 10% discount:

let discounted = [Link](p => p * 0.9);[Link](discounted); //


[90, 45, 180, 27]

map() changes each item and returns a new array.

Q3. Why Use Event Delegation in To-Do List?

Imagine we have a <ul> with many <li> items. We want to handle clicks on each
item. Instead of doing this:

[Link]("click", ...);[Link]("click", ...);


We do this:

[Link]("click", function(e) {
if ([Link] === "LI") {
// handle click
}});

✅ Benefits of Event Delegation:

- Only one listener for all items

- Works for new items added later

- Less memory usage

- Cleaner and easier code

It’s like putting one security guard at the door instead of one at every room.

Q4. Role of [Link]() in Form Validation

When a form is submitted, the browser reloads the page by default.

[Link]("submit", function(event) {
[Link]();
// validation logic here});

🛑 What it stops:

-The default form submission (page reload)

✅ Why it’s needed:

-Lets you show error messages before the form is sent

-Keeps the user on the same page

-Makes validation work properly

Without it, the page reloads too fast and skips your custom checks.

Q5. Difference Between JS Object and JSON

JavaScript Object:

let person = { name: "Ali", age: 25 };

- Keys don’t need quotes

- Can include functions and other types


{ "name": "Ali", "age": 25 }

- Keys must be in double quotes

-Only supports data (no functions)

You might also like