0% found this document useful (0 votes)
12 views

css imp

Uploaded by

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

css imp

Uploaded by

RUTIKA WAGHMARE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Q.

SYNTAX AND EXPLAIN FOR-IN LOOP


1.For-in loop in JavaScript is used to iterate over
the properties of an object.
2.Certainly, for objects, the for-in loop allows
you to get the property name in the iteration
variable
3.for (x in object) { code block to be executed }
4.<script>
var code= {
CO : "Comp Engg.",
IF : "Info Tech",
Q.Differentiate between scabstring() and substr()
method of a string Give suitable example of each

Feature substr() substring()

str.substring(start,
str.substr(start, length)
Syntax end)

Parameters start: Starting index start: Starting index

length: Number of end: Ending index


Length characters to extract (exclusive)

Accepts
Does not accept
negative start (counts
negative start or end
Negative Index from the end)

If start is negative, it’s


If either start or end is
treated as str.length +
negative, they are
Behavior with start. If length is
treated as 0.
Negative Index negative, it’s ignored.

If length is omitted, If end is omitted,


Handling Omitted extracts characters to extracts characters to
Parameters the end of the string. the end of the string.
Q.State what is a cookie? Explain its need state characteristics of persistent cookies.
(Describe how to read cookie-value and unite cookie value)
ANS :-
1. A "cookie" is a small text file stored on a user's computer by a website, containing
information about the user's browsing activity on that site, allowing the website
to remember details like login status, preferences, or items in a shopping cart,
essentially personalizing the user experience across multiple visits; "persistent
cookies" are a type of cookie that remain on the user's device even after the
browser is closed, with an expiration date set, enabling websites to retain user
information across multiple sessions.
2. Characteristics of Persistent Cookies:
 Expiration Date:
Unlike session cookies which expire when the browser closes, persistent cookies have a
set expiration date, meaning they remain on the user's device until that date is reached.
 Long-Term Data Storage:
This feature allows websites to store information that needs to be remembered across
multiple browsing sessions, like login details or user preferences.
3. Reading a Cookie Value:
 JavaScript:
Most web browsers provide access to cookies through
JavaScript's document.cookie property. To read a cookie named "username", you would
use the code: document.cookie.split(';').filter(cookie =>
cookie.startsWith('username=')).map(cookie => cookie.split('=')[1])[0].
 Server-Side Languages (e.g., PHP):
On the server-side, you can access cookie values using built-in variables
like $_COOKIE['cookieName'] in PHP.
Key points to remember:
 User Consent:
Due to privacy regulations, websites should always obtain user consent before setting
persistent cookies.
 Cookie Management:
Users can manage their cookies through browser settings, including deleting or blocking
specific cookies.
Q. Give syntax of and explain the use of setTime out() function with the help
of suitable example.
1. The setTimeout() method executes a block of code after the specified time. The
method executes the code only once.

2. The commonly used syntax of JavaScript setTimeout is:

 setTimeout(function, milliseconds);

 example
 // program to display a text using setTimeout method
 function greet() {
 console.log('Hello world');
 }

 setTimeout(greet, 3000);
 console.log('This message is shown first');

4. The setTimeout() method is useful when you want to


execute a block of once after some time. For example,
showing a message to a user after the specified time.

5. The setTimeout() method calls the function only once after the
time interval (here 3 seconds).
6. However, in the above program, since the function is calling itself,
the program displays the time every 3 seconds.
7. This program runs indefinitely (until the memory runs out).

8. Note: If you need to execute a function multiple times, it's better to


use the setInterval() method.
Q. Explain getter and setter properties in JavaScript with
suitable example.
Ans: JavaScript object accessors are used to access and update the
objects. Getter and setter are used as object
accessors to get or set object properties.
Getter method helps in accessing the object methods as object
properties.
Setter method is used to set object pro
perties.
Using getter and setter the javascript provides better data security
and data quality.
Example:
<!DOCTYPE html>
<html>
<body>
<script>
var car = {
brand: "Toyota",
color: "Blue",
get getBrand () {
return this.brand;
},
get getColor () {
return this.color;
},
set setBrand (newBrand) {
this.brand = newBrand;
},
set setColor (newColor) {
this.color = newColor;
}
};
document.write("Car Brand: " + car.brand + "<br>Car Color: " + car.color);
car.setBrand = "Tesla";
car.setColor = "Red";
document.write("<br><br>Car Brand: " + car.brand + "<br>Car Color: " +
car.color);
</script>
</body>
</html>
Q. write the use of charCodeAt() and fromCharCode method
with syntax and example.
ANS =
1. The charCodeAt() method returns the Unicode of the
character at a specified index (position) in a string.
2. The index of the first character is 0, the second is 1, ....
3. The index of the last character is string length - 1 (See
Examples below).
See also the charAt() method.
4. The syntax of the fromCharCode() method is:
String.fromCharCode(num1, ..., numN)
5. The fromCharCode() method, being a static method, is
called using the String class name.

6. EXAMPLE = // use of fromCharCode()


let string1 = String.fromCharCode(72, 69, 76, 76, 79);

// printing the equivalent characters


console.log(string1);
Q. Ditterentiate between push() and joine() method of array object with respect to use
syntax, return value and example.
ANS=
Q. Explain splice() method of array object with syntax and example.
ANS=

The splice() method can be used to add new items to an array, and removes elements
from an array. Syntax:
arr.splice(start_index,removed_elements,list_of_elemnts_to_be_added); Parameter:
•The first parameter defines the position where new elements should be added
(spliced in). •The second parameter defines how many elements should be removed.
•The list_of_elemnts_to_be_added parameter define the new elements to be
added(optional). Output:
The splice() method can be used to add new items to an array, and removes elements
from an array.
Syntax: arr.splice(start_index,removed_elements,list_of_elemnts_to_be_added);
Parameter:
•The first parameter defines the position where new elements should be added
(spliced in).
•The second parameter defines how many elements should be removed.
•The list_of_elemnts_to_be_added parameter define the new elements to be
added(optional).
EXAMPLE=
<html>
<body>
<script>
var fruits = ["Banana", "Watermelon", "Chikoo", "Mango", "Orange", "Apple"];
document.write(fruits+"<br>");
fruits.splice(2,2, "Lemon", "Kiwi");
document.write(fruits+"<br>");
fruits.splice(0,2); //removes first 2 elements from array
document.write(fruits+"<br>");
</script>
</body>
</html>
Q. list ways of protecting your web page and describle any one of them.
ANS =
1) Hiding Your Code by disabling Right Mouse Click:
2) Hiding JavaScript
3) Concealing Your E-mail Address
 There is nothing secret about your web page. Anyone with a little computer
knowledge can use a few mouse clicks to display your HTML code, including your
JavaScript, on the screen. Following are the ways to protect web pages: 1) Hiding
Your Code by disabling Right Mouse Click: The following example shows you how
to disable the visitor's right mouse button while the browser displays your web page.
All the action occurs in the JavaScript that is defined in the tag of the web page. There
is nothing secret about your web page. Anyone with a little
 computer knowledge can use a few
 mouse clicks to display your HTML code, including your JavaScript, on the
 screen.
 Following are the ways to protect web pages:
1) Hiding Your Code by disabling Right Mouse Click:
 The following example shows you how to disable the visitor's right mouse
 button while the browser
 displays your web page. All the action occurs in the JavaScript that is
 defined in the <head> tag of the
web page.
<html>
<head>
<script>
window.onload = function()
{
document.addEventListener("contextmenu", function(e)
{
e.preventDefault();
}, false);}
</script>
<body>
<h3>Right click on screen,Context Menu is disabled</h3>
</body>
</html>
 The preventDefault() method cancels the event if it is cancelable, meaning
 that the default action that
 belongs to the event will not occur.
Q. Explain how to create and display Rotating Banner in JavaScript with example. ]
Ans: Following steps must be follow for creating banner in javascript:
1. Load banner advertisements into an array.
2. Determine whether the browser supports the image object.
3. Display a banner advertisement. 4. Pause before displaying the next banner
advertisement. EXAMPLE
Q. Explain text and image rollover with suitable example.

Ans: Text rollover: We can also create a rollover and rollback for text using the onmouseover
and onmouseout.
EXAMPLE:
<html>
<head>
Q. Write a javascript program to demonstrate java intrinsic function.
ANS= An intrinsic function is often used to replace the Submit button and the Reset button
with your own graphical images, which are displayed on a form in place of these buttons.
Q.Describe how to link banner advertisement to URL with example.
ANS= The banner advertisement is the hallmark of every commercial web page. It is typically
positioned near the top of the web page, and its purpose is to get the visitor's attention by
doing all sorts of clever things. To get additional information, the visitor is expected to click
the banner so that a new web page opens. You can link a banner advertisement to a web
page by inserting a hyperlink into your web page that calls a JavaScript function rather than
the URL of a web page. The JavaScript then determines the URL that is associated with the
current banner and loads the web page that is associated with the URL.
Q.State what is regular expression. Explain its meaning with the help of a suitable example.
ANS= A regular expression is an object that describes a pattern of characters. The JavaScript
RegExp class represents regular expressions, and both String and RegExp define methods
that use regular expressions to perform powerful pattern-matching and search-and-replace
functions on text. A Regular Expression is a sequence of characters that constructs a search
pattern. When you search for data in a text, you can use this search pattern to describe what
you are looking for.
Syntax: A regular expression is defined with the RegExp () constructor as: var pattern = new
RegExp(pattern, attributes);

You might also like