CSS Ut 2 Answer Key Harshal Mahadik
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:`
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).
Example:
Math.sqrt(16) returns 4.
Math.sqrt(2) returns approximately 1.414.
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:
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:
Q10:-
1. submit
2. reset
3. change
4. input
5. focus
6. blur
7. select
8. invalid
9. keydown
10. keyup