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

Q1 Javascript Answers

The document outlines key features of JavaScript, including its lightweight nature and platform independence. It differentiates between session and persistent cookies, provides a JavaScript program to check for prime numbers, and explains various form events. Additionally, it discusses popular JavaScript frameworks and their applications, along with examples of manipulating window content and accessing elements in child windows.

Uploaded by

thoratatul131
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)
28 views3 pages

Q1 Javascript Answers

The document outlines key features of JavaScript, including its lightweight nature and platform independence. It differentiates between session and persistent cookies, provides a JavaScript program to check for prime numbers, and explains various form events. Additionally, it discusses popular JavaScript frameworks and their applications, along with examples of manipulating window content and accessing elements in child windows.

Uploaded by

thoratatul131
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

Q.

1 Attempt any FIVE of the following: (10 Marks)

(a) State the features of JavaScript.

Answer:

1. Lightweight scripting language

2. Interpreted and not compiled

3. Object-based and event-driven

4. Can be used for client-side as well as server-side development

5. Platform-independent

6. Provides control over browser behavior

(b) Differentiate between session cookies and persistent cookies.

Answer:

| Feature | Session Cookies | Persistent Cookies |

|---------------------|--------------------------------------|------------------------------------------|

| Lifespan | Temporary, deleted when browser closes | Remains until a set expiration date |

| Storage | Stored in memory | Stored on the user's device (hard disk) |

| Use Case | Login sessions, temporary preferences | Remember user login, preferences

(c) Write a JavaScript program to check whether entered number is prime or not.

Answer:

function isPrime(num) {

if (num <= 1) return false;

for (let i = 2; i < num; i++) {

if (num % i === 0) return false;


}

return true;

let number = parseInt(prompt("Enter a number:"));

if (isPrime(number)) {

alert(number + " is a prime number.");

} else {

alert(number + " is not a prime number.");

(d) Explain following form events:

(i) onmouseup

Answer: Triggered when the mouse button is released over an element.

(ii) onblur

Answer: Triggered when an input field loses focus.

(e) Write a JavaScript program to changing the contents of a window.

Answer:

<p id="demo">Original content</p>

<button onclick="changeContent()">Change</button>

<script>

function changeContent() {

document.getElementById("demo").innerHTML = "Content changed!";

</script>
(f) Explain frameworks of JavaScript and its application.

Answer:

Popular JavaScript frameworks:

1. React.js - Used for building user interfaces.

2. Angular - A powerful framework for single-page applications.

3. Vue.js - Lightweight framework for building interactive web interfaces.

4. Node.js - Enables server-side JavaScript.

Applications: Web development, mobile app development, real-time apps, and APIs.

(g) Write a JavaScript syntax to access elements of another child window.

Answer:

let childWindow = window.open("child.html");

childWindow.document.getElementById("elementID").value = "Updated value";

You might also like