0% found this document useful (0 votes)
20 views5 pages

CSS Ut 2 Answer Key Harshal Mahadik

Uploaded by

yiwav67616
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)
20 views5 pages

CSS Ut 2 Answer Key Harshal Mahadik

Uploaded by

yiwav67616
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
You are on page 1/ 5

CSS UT 2 ANSWER KEY HARSHAL MAHADIK

2MARKS QUESTIONS:-
Q1:-
Properties of the `location` Object

1. location.href
Represents the full URL of the current page.
Example: `console.log(location.href);` might output `https://example.com/page` if
the URL is `https://example.com/page`

2. location.hostname
Returns the domain name of the web host.
Example: If the URL is `https://example.com/page`,
`console.log(location.hostname);` outputs `example.com`

3. location.pathname
Returns the path of the URL, excluding the domain.
Example: If the URL is `https://example.com/page/subpage`,
`console.log(location.pathname);` outputs `/page/subpage`

4. location.protocol
Returns the protocol used by the URL (e.g., `http:` or `https:`).
Example: If the URL is `https://example.com`, `console.log(location.protocol);`
outputs `https:`

Methods of the `location` Object

1. location.reload()
Reloads the current page.
Example: `location.reload();` refreshes the page as if the user pressed the refresh
button

2. location.assign()
Loads a new document in the current tab or window.
Example: `location.assign("https://example.com");` navigates to
`https://example.com`
3. location.replace()
Replaces the current document with a new one, without saving the previous URL in
session history.
Example: `location.replace("https://example.com");` navigates to
`https://example.com` without adding the current page to history

4. location.toString()
Returns the entire URL as a string, equivalent to `location.href`.
Example: `console.log(location.toString());` outputs the full URL, such as
`https://example.com/page`

Q2:-

A **session cookie** is a temporary cookie that stores information for the duration of
a user's visit to a website. It is automatically deleted when the user closes the browser,
making it useful for maintaining temporary session data, such as login status or items
in a shopping cart.

Example in JavaScript:

```javascript
// Set a session cookie
document.cookie = "sessionID=123456; path=/";
```

This cookie will store `sessionID` for the session but will be deleted once the browser
is closed.
Q3:-
1. Use HTTPS
2. Implement strong authentication (e.g., OAuth, 2FA)
3. Use Content Security Policy (CSP)
4. Validate and sanitize user inputs
5. Disable directory listing
6. Set secure HTTP headers (e.g., X-Content-Type-Options, X-XSS-Protection)
7. Use server-side validation
8. Minimize use of cookies or set them with HttpOnly and Secure flags
9. Prevent Cross-Site Scripting (XSS)
10. Implement Cross-Site Request Forgery (CSRF) tokens
11. Restrict file uploads and validate file types
12. Use strong passwords for access
13. Keep software and frameworks updated
14. Hide sensitive files and directories
15. Disable unnecessary features (e.g., auto-indexing)
16. Implement access control mechanisms
17. Use a Web Application Firewall (WAF)
18. Protect against SQL Injection
19. Monitor and log access attempts
20. Use CAPTCHA to prevent bots.

Q5:-

· parseInt()
Converts a string into an integer. It parses the string until it encounters a non-numeric character.
Example: parseInt("123abc") returns 123.

· setTimeout()
Executes a function after a specified delay in milliseconds.
Example: setTimeout(() => console.log("Hello"), 1000) logs "Hello" after 1 second.

· Date()
Creates a new date object representing the current date and time.
Example: new Date() might return Mon Nov 18 2024 10:00:00 GMT+0000 (UTC).

Math.sqrt() is an intrinsic JavaScript function. It calculates the square root of a number.

Example:
Math.sqrt(16) returns 4.
Math.sqrt(2) returns approximately 1.414.

If you pass a negative number, it will return NaN (Not-a-Number).


Q6:-

Aspect JavaScript (JS) JavaScript Framework


Core programming language Pre-built structure and set of tools to
Definition
used for web development. simplify JS code.
Offers predefined solutions,
Provides basic functionalities for
Usage templates, and methods for complex
creating dynamic web content.
applications.
Complete control over code Framework dictates structure,
Control
structure and flow. reducing developer control.
Learning Generally simpler and Requires learning the framework's
Curve foundational to learn. conventions and syntax.
Examples JavaScript itself (vanilla JS). React, Angular, Vue, etc.
Often lightweight, depends on Optimized for specific tasks but can
Performance
developer optimizations. be heavier due to added features.
Q9:-
Aspect Pop-Up Menu Context Menu
A temporary menu that appears on A menu that appears on right-click,
Definition the screen, typically initiated by a providing options related to the
user action. specific item clicked.
Appears specifically when right-
Can appear from any action, like a
Trigger Action clicking or long-pressing on an
button click or specific event.
item.
Provides general options or
Offers context-specific options
Purpose navigation, usually for multiple
based on where the user clicks.
tasks.
Can appear in various parts of the Appears right at the point of
Location
interface, often at a fixed location. interaction (where the user clicks).
A context menu on a file for
Usage A pop-up menu for navigation
options like "Open," "Rename," or
Example options or settings.
"Delete."
Typically limited to the designer’s Often dynamically generated based
Customization
specifications. on the object or area clicked.
Q8:-

source
Use: Returns the string value of the regular expression pattern. It gives the pattern
used for the RegExp object.
Example:
const regex = /abc/;console.log(regex.source); // Outputs: "abc"

global
Use: A boolean value that indicates whether the g flag is set in the regular expression, which means
global matching (finding all matches in a string).
Example:

const regex = /a/g;console.log(regex.global); // Outputs: true

lastIndex
Use: Specifies the index at which to start the next match. It is used when performing multiple
matches with methods like exec() and test().
Example:

const regex = /a/g;


regex.lastIndex = 2;console.log(regex.exec("banana")); // Starts searching from index 2

Q10:-
1. submit
2. reset
3. change
4. input
5. focus
6. blur
7. select
8. invalid
9. keydown
10. keyup

You might also like