You are on page 1of 23

HTML

1.What is HTML?

Ans:

 HTML is short for HyperText Markup Language, and is the language of the World Wide Web.

 It is the standard text formatting language used for creating and displaying pages on the
Web.

 HTML documents are made up of two things: the content and the tags that formats it for
proper display on pages.

2.What are tags?

Ans:

Content is placed in between HTML tags 0in order to properly format it. It makes use of the less than
symbol (<) and the greater than symbol (>).

3.Do all HTML tags come in pair?

Ans:

No, there are single HTML tags that does not need a closing tag. Examples are the < img> tag and <
br> tags.

4.What are some of the common lists that can be used when designing a page?

Ans:

You can insert any or a combination of the following list types:

– ordered list

– unordered list

– definition list

– menu list

– directory list

Each of this list types makes use of a different tag set to compose

5.What is the difference between HTML elements and tags?

Ans:

HTML elements communicate to the browser how to render text. When surrounded by angular
brackets < > they form HTML tags. For the most part, tags come in pairs and surround text.

6.What is head in HTML document?

Ans:
 The head of an HTML document is an unordered collection of information about the
document.

 The HEAD contains general information, or meta-information, about the document.

 The head appears first in a document above the BODY.

7.What is “Semantic HTML?”

Ans:

 Semantic HTML is a coding style where the tags embody what the text is meant to convey.

 In Semantic HTML, tags like < b> < /b> for bold, and < i> < /i> for italic should not be used,
reason being they just represent formatting, and provide no indication of meaning or
structure.

 The semantically correct thing to do is use < strong> < /strong> and < em> < /em> .

 These tags will have the same bold and italic effects, while demonstrating meaning and
structure (emphasis in this case).

8.What does DOCTYPE mean?

Ans:

The term DOCTYPE tells the browser which type of HTML is used on a webpage.

In turn, the browsers use DOCTYPE to determine how to render a page.

Failing to use DOCTYPE or using a wrong DOCTYPE may load your page in Quirks Mode. See
example:< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">.

9.What’s the difference between standards mode and quirks mode?

Ans:

Quirks Mode is a default compatibility mode and may be different from browser to browser,
which may result to a lack of consistency in appearance from browser to browser.

10.Do all character entities display properly on all systems?

Ans:

No, there are some character entities that cannot be displayed when the operating system
that the browser is running on does not support the characters. When that happens, these
characters are displayed as boxes.

11.What is image map?

Ans:

Image map lets you link to many different web pages using a single image. You can define shapes in
images that you want to make part of an image mapping.
12.What is the advantage of collapsing white space?

Ans:

White spaces are blank sequence of space characters, which is actually treated as a single space
character in html. Because the browser collapses multiple space into a single space,
you can indent lines of text without worrying about multiple spaces. This enables you to organize the
html code into a much more readable format.

13.Can attribute values be set to anything or are there specific values that they accept?

Ans:

Some attribute values can be set to only predefined values. Other attributes can accept any
numerical value that represents the number of pixels for a size.

14.How do you insert a copyright symbol on a browser page?

Ans:

To insert the copyright symbol, you need to type © or & #169; in an HTML file.

15.How do you create links to sections within the same page?

Ans:

Links can be created using the tag, with referencing through the use of the number (#) symbol

16.Is there any way to keep list elements straight in an html file?

Ans:

 By using indents, you can keep the list elements straight.

 If you indent each subnested list in further than the parent list that contains it, you can at a
glance determine the various lists and the elements that it contains.

17.If you see a web address on a magazine, to which web page does it point?

Ans:

 Every web page on the web can have a separate web address.

 Most of these addresses are relative to the top-most web page.

 The published web address that appears within magazines typically points this top-most
page.

 From this top level page, you can access all other pages within the web site.

18.What is the use of using alternative text in image mapping?

Ans:
When you use image maps, it can easily become confusing and difficult to determine which
hotspots corresponds with which links. Using alternative text lets you put a descriptive text
on each hotspot link.

19.Do older html files work on newer browsers?

Ans:

Yes, older html files are compliant to the HTML standard. Most older files work on the newer
browsers, though some features may not work.

20.Does a hyperlink apply to text only?

Ans:

No, hyperlinks can be used on text as well as images. That means you can convert an image
into a link that will allow user to link to another page when clicked. Just surround the image
within the < a href=” “> …< /a> tag combinations.

21.If the user’s operating system does not support the needed character, how can the symbol be
represented?

Ans:

In cases wherein their operating system does not support a particular character, it is still possible to
display that character by showing it as an image instead.

22.How do you change the number type in the middle of a list?

Ans:

The < li > tag includes two attributes – type and value. The type attribute can be used to change the
numbering type for any list item. The value attribute can change the number index.

23.What are style sheets?

Ans:

Style sheets enable you to build consistent, transportable, and well-defined style templates. These
templates can be linked to several different web pages, making it easy to maintain and change the
look and feel of all the web pages within a site.

24.What bullet types are available?

Ans:

With ordered lists, you can select to use a number of different list types including alphabetical and
Roman numerals. The type attribute for unordered lists can be set to disc, square, or circle.

25.How do you create multicolored text in a webpage?

Ans:
To create text with different colors, use the < font color=”color”> …< /font> tags for every character
that you want to apply a color. You can use this tag combination as many times as needed,
surrounding a single character or an entire word.

26.Why are there both numerical and named character entity values?

Ans:

 The numerical values are taken from the ASCII values for the various characters, but these
can be difficult to remember.

 Because of this, named character entity values were created to make it easier for web page
designers to use.

27.What is the advantage of grouping several checkboxes together?

Ans:

 Although checkboxes don’t affect one another, grouping checkboxes together helps to
organize them.

 Checkbox buttons can have their own name and do not need to belong to a group.

 A single web page can have many different groups of checkboxes.

28.What are the limitations when serving XHTML pages?

Ans:

Perhaps the biggest issue is the poor browser support XHTML currently enjoys.

Internet Explorer and a number of other user agents cannot parse XHTML as XML.

Thus, it is not the extensible language it was promised to be.

There are many other issues.

Take your pick.

29.How many HTML tags are should be used for the most simple of web pages?

Ans:

8 total. 4 pairs of tags.

< HTML> < HEAD > < TITLE > Simplest page ever! < /TITLE > < /HEAD > < BODY > Doesn’t get simpler
than this. < /BODY > < /HTML >

30.How do you make comments without text being picked up by the browser?

Ans:

Comments are used to explain and clarify code or to prevent code from being recognized by the
browser. Comments start with “*< !--” and end with ” --> “.

< !-- Insert comment here. -->

31.What is the difference between linking to an image, a website, and an email address?
Ans:

To link an image, use < img> tags. You need specify the image in quotes using the source attribute,
src in the opening tag. For hyperlinking, the anchor tag, < a> , is used and the link is specified in the
href attribute. Text to be hyperlinked should be placed between the anchor tags. Little known fact:
href stands for “hypertext reference.” When linking to an email, the href specification will be
“mailto:send@here.com.” See examples below:

< img src=”HTMLrocks.jpg”> < /img>

< a href=”www.allindiaexams.in”> All India Exams< /a>

< a href=”admin@allindiaexams.in”> Email Me< /a>

32.What is the syntax difference between a bulleted list and numbered list?

Ans:

Bulleted lists use the < ul > tag, which stands for “unordered,” whereas < ol > is used to create an
ordered list.

33.< h2 > What is the difference between < div > and < frame > ?

< /h2 >

Ans:

A < div > is a generic container element for grouping and styling, whereas a < frame > creates
divisions within a web page and should be used within the < frameset > tag. The use of < frame > and
< frameset > are no longer popular and are now being replaced with the more flexible < iframe > ,
which has become popular for embedding foreign elements (ie. Youtube videos) into a page.

34.What are the reasons for validating a HTML?

Ans:

To ensure one shared HTML coding standard in the World Wide WebTo ensure smooth spiderability
of the HTML pageTo ensure better positioning of the HTML in Search Engines

35.What is span in HTML?

Ans:

The SPAN having notation as

< SPAN > < /SPAN >

is used for highlighting text of any color desired, for adding colored text, for adding background
image to text.

SPAN doesn't cause a line break. It delimits text and it allows styles to be applied to a 'elemental'
region, or for the 'elemental' region to be identified, without causing a break in the text flow.

36.What is contained in HTML markup?

Ans:
It consists of :

1. Character-based data types

2. Several key components, including elements (and their attributes)

3. Character references and entity references.

4. Also the document type declaration.

37.What is body in HTML document?

Ans:

The body element defines the documents' body. It contains all the contents of the document (like
text, images, colors, graphics, etc.).

38.How do you make decision when to use use HTML & xHTML ?

Ans:

HTML and XHTML are very similar, but XHTML follows a stricter set of rules, making it easier to
validate data and design pages

CSS
1.What is CSS ?

Ans:

1. CSS stands for Cascading Style Sheets and is a simple styling language which allows attaching style
to HTML elements. Every element type as well as every occurrence of a specific element within that
type can be declared an unique style, e.g. margins, positioning, color or size.

2. CSS is a web standard that describes style for XML/HTML documents.

3. CSS is a language that adds style (colors, images, borders, margins…) to your site. It’s really that
simple. CSS is not used to put any content on your site, it’s just there to take the content you have
and make it pretty. First thing you do is link a CSS-file to your HTML document.

2.Is CSS case sensitive?

Ans:

 Cascading Style Sheets (CSS) is not case sensitive.

 However, font families, URLs to images, and other direct references with the style sheet may
be.

 The trick is that if you write a document using an XML declaration and an XHTML doctype,
then the CSS class names will be case sensitive for some browsers.
3.What is a class? What is an ID?

Ans:

A class is a style (i.e., a group of CSS attributes) that can be applied to one or more HTML elements.

This means it can apply to instances of the same element or instances of different elements to which
the same style can be attached.

Classes are defined in CSS using a period followed by the class name.

It is applied to an HTML element via the class attribute and the class name.

The following snippet shows a class defined, and then it being applied to an HTML DIV element.

.test {font-family: Helvetica; font-size: 20; background: black;}

test

Also, you could define a style for all elements with a defined class. This is demonstrated with the
following code that selects all P elements with the column class specified.

p.column {font-color: black;}

An ID selector is a name assigned to a specific style.

In turn, it can be associated with one HTML element with the assigned ID.

Within CSS, ID selectors are defined with the # character followed by the selector name.

The following snippet shows the CSS example1 defined followed by the use of an HTML element’s ID
attribute, which pairs it with the CSS selector.

#example1: {background: blue;}

4.What are properties of style sheet ?

Ans:

CSS Background

CSS Text

CSS Font

CSS Border

CSS Outline

CSS Margin
CSS Padding

CSS List

CSS Table

5.What are the limitations of CSS ?

Ans:

Limitations are:

• Ascending by selectors is not possible

•Limitations of vertical control

•No expressions

•No column declaration

•Pseudo-class not controlled by dynamic behavior

•Rules, styles, targeting specific text not possible

6.What are the advantages of CSS ?

Ans:

Advantages are:

•Bandwidth

•Site-wide consistency

•Page reformatting

•Accessibility

•Content separated from presentation

7.List the various font attributes used in style sheet

Ans:

font-style

font-variant

font-weight

font-size/line-height

font-family

caption, icon, menu, message-box, small-caption, status-bar.

8.What is the difference between an ID selector and CLASS?

Ans:
An ID selector identifies and sets style to only one occurrence of an element, while CLASS can be
attached to any number of elements.

9.What is Contextual Selector?

Ans:

 Contextual selector addresses specific occurrence of an element.

 It is a string of individual selectors separated by white space (search pattern), where only the
last element in the pattern is addressed providing it matches the specified contex

10.What is Grouping?

Ans:

When more than one selector shares the same declaration, they may be grouped together via a
comma-separated list; this allows you to reduce the size of the CSS (every bit and byte is important)
and makes it more readable. The following snippet applies the same background to the first three
heading elements.

11.What are Child Selectors?

Ans:

 A child selector is used when you want to match an element that is the child of another
specific element.

 The parent and child selectors are separated by spaces.

 The following selector locates an unordered list element within a paragraph element and
makes a text within that element bold.

p > ul {font-weight: bold;}

12.What are Pseudo Classes?

Ans:

Pseudo classes allow you to identify HTML elements on characteristics (as opposed to their name or
attributes).

The classes are specified using a colon to separate the element name and pseudo class.

A good example is the :link and :visited pseudo classes for the HTML A element.

Another good example is first-child, which finds an element’s first child element.

The following CSS makes all visited links red and green, the actual link text becomes yellow when the
mouse pointer is positioned over it, and the text of the first element of a paragraph is bold.

a:link {font-color: red;}

a:visited {font-color: green;}

a:hover {font-color: yellow;}

p.first-child {font-weight: bold;}


13.What does z-index do?

Ans: The z-index property specifies the stack order of an element. An element with greater stack
order is always in front of an element with a lower stack order. Here is the Example, where using z-
index property you can display in front of image.

16.What benefits and demerits do External Style Sheets have?

Ans:

Benefits:

•One file can be used to control multiple documents having different styles.

•Multiple HTML elements can have many documents, which can have classes.

•To group styles in composite situations, methods as selector and grouping are used.

Demerits:

•Extra download is needed to import documents having style information.

•To render the document, the external style sheet should be loaded.

•Not practical for small style definitions.

17.Discuss the merits and demerits of Embedded Style Sheets?

Ans:

Merits of Embedded Style Sheets:

•Multiple tag types can be created in a single document.

•Styles, in complex situations, can be applied by using Selector and Grouping methods.

•Extra download is unnecessary.

Demerits of Embedded Style Sheets:

•Multiple documents cannot be controlled.

18.What is CSS rule ‘ruleset’?

Ans:

There are two types of CSS rules: —> ruleset and at-rule.

Ruleset identifies selector or selectors and declares style which is to be attached to that selector or
selectors. For example P
{text-indent: 10pt} is a CSS rule. CSS rulesets consist of two parts: selector, e.g. P and declaration, e.g.
{text-indent: 10pt}.

P {text-indent: 10pt} – CSS rule (ruleset)

{text-indent: 10pt} – CSS declaration

text-indent – CSS property

10pt – CSS value

19.What is imported Style Sheet? How to link?

Ans: Imported Style Sheet is a sheet that can be imported to (combined with) another sheet. This
allows creating one “main sheet” containing declarations that apply to the whole site and” partial
sheets” containing declarations that apply to specific elements (or documents) that may require
additional styling. By importing partial sheets to the main sheet a number of sources can be
combined into one. To import a style sheet or style sheets include the @import notation or notations
in the STYLE element. The @import notations must come before any other declaration. If more than
one sheet is imported they will cascade in order they are imported – the last imported sheet will
override the next last; the next last will override the second last, and so on. If the imported style is in
conflict with the rules declared in the main sheet then it will be overridden.

21.How do I combine multiple sheets into one?

Ans: To combine multiple/partial style sheets into one set the TITLE attribute taking one and the
same value to the LINK element. The combined style will apply as a preferred style, e.g.

< LINK REL=Stylesheet HREF=”default.css” TITLE=”combined” >

< LINK REL=Stylesheet HREF=”fonts.css” TITLE=”combined” >

< LINK REL=Stylesheet HREF=”tables.css” TITLE=”combined” >

22.What is parent-child selector?

Ans:

Parent-child selector is a selector representing the direct descendent of a parent element. Parent-
child selectors are created by listing two or more tilde (~) separated selectors.

BODY ~ P {background: red; color: white}

The P element will be declared the specified style only if it directly descends from the BODY
element:

< BODY& gt; < P > Red and white paragraph < /P > < /BODY >

BODY ~ P ~ EM {background: red; color: white}

The EM element will be declared the specified style only if it directly descends from the P element
which in its turn directly descends from the BODY element:
< P > < EM> Red and white EM < /EM > < /P > < /BODY >

23.How can I specify background images?

Ans:

With CSS, you can suggest a background image (and a background color, for those not using your
image) with the background property. Here is an example:

body {

background: white url(example.gif) ;

color: black ;

If you specify a background image, you should also specify text, link, and background colors since
the reader’s default colors may not provide adequate contrast against your background image. The
background color may be used by those not using your background image. Authors should not rely
on the specified background image since browsers allow their users to disable image loading or to
override document-specified backgrounds.

24.How do I have a fixed (non-scrolling) background image?

Ans:

With CSS, you can use the background-attachment property. The background attachment can be
included in the shorthand background property, as in this example:

body {

background: white url(example.gif) fixed ;

color: black ;

Note that this CSS is supported by Internet Explorer, Mozilla, Firefox Opera, Safari, and other
browsers. In contrast, Microsoft’s proprietary BGPROPERTIES attribute is supported only by Internet
Explorer.
JAVA SCRIPT
1.What is JavaScript?

Ans:

JavaScript is a general-purpose programming language designed to let programmers of all skill levels
control the behavior of software objects.

 The language is used most widely today in Web browsers whose software objects tend to
represent a variety of HTML elements in a document and the document itself.

 But the language can be--and is--used with other kinds of objects in other environments.

 For example, Adobe Acrobat Forms uses JavaScript as its underlying scripting language to
glue together objects that are unique to the forms generated by Adobe Acrobat.

 Therefore, it is important to distinguish JavaScript, the language, from the objects it can
communicate with in any particular environment.

 When used for Web documents, the scripts go directly inside the HTML documents and are
downloaded to the browser with the rest of the HTML tags and content.

2.Is JavaScript case sensitive?

Ans:

 Yes, absolutely. For example, the function getElementById is not the same as the function
getElementbyID. Keeping your capitalization consistent is important.

 JavaScript is a platform-independent, event-driven, interpreted client-side scripting and


programming language developed by Netscape Communications Corp. and Sun
Microsystems.

3.Are Java and JavaScript the Same?

Ans:

 No. java and JavaScript are two different languages.

 Java is a powerful object - oriented programming language like C++, C whereas JavaScript is a
client-side scripting language with some limitations.

4.What is ‘this’ keyword in JavaScript?

Ans:

‘This’ keyword is used to point at the current object in the code. For instance: If the code is presently
at an object created by the help of the ‘new’ keyword, then ‘this’ keyword will point to the object
being created.

5.Explain the different types of pop-up boxes you can create in JavaScript.
Ans:

There are three main types of pop-up boxes in JavaScript: alert boxes, confirm boxes, and prompt
boxes.

•Alert Box: Used to confirm that a user understands a vital piece of information before proceeding.
The user must click OK to exit the box.

window.alert("Alert text here."); •Confirm box:a Used when user verification is required. It will
return TRUE if the user clicks OK, and FALSE if the user clicks CANCEL.

window.confirm("Confirm text here."); •Prompt box: Used if the user needs to input something
before proceeding. When the user inputs a value and presses OK, the prompt box will return the
input value. If the user clicks CANCEL without inputting a value, the input value will return as null.

window.prompt("Prompt box text","Default value");

6.What are JavaScript Data Types?

Ans:

JavaScript Data Types are Number, String, Boolean, Function, Object, Null, Undefined

7.What looping structures are there in JavaScript?

Ans:

JavaScript supports the for loop, while loop, do-while loop, but there is no foreach loop in JavaScript.

8.What are the different boolean operators in JavaScript?

Ans:

•&& – the “and” operator.

•|| – the “or” operator.

•! – the “not” operator.

9.How is JavaScript different from Java?

Ans:

avaScript was developed by Brendan Eich of Netscape Java was developed at Sun Microsystems.
While the two languages share some common syntax, they were developed independently of each
other and for different audiences. Java is a full-fledged programming language tailored for network
computing it includes hundreds of its own objects, including objects for creating user interfaces that
appear in Java applets (in Web browsers) or standalone Java applications. In contrast, JavaScript
relies on whatever environment it's operating in for the user interface, such as a Web document's
form elements.

JavaScript was initially called LiveScript at Netscape while it was under development. A licensing deal
between Netscape and Sun at the last minute let Netscape plug the "Java" name into the name of its
scripting language. Programmers use entirely different tools for Java and JavaScript. It is also not
uncommon for a programmer of one language to be ignorant of the other. The two languages don't
rely on each other and are intended for different purposes. In some ways, the "Java" name on
JavaScript has confused the world's understanding of the differences between the two. On the other
hand, JavaScript is much easier to learn than Java and can offer a gentle introduction for newcomers
who want to graduate to Java and the kinds of applications you can develop with it.

10.What is the difference between == and === ?

Ans:

The == checks for value equality, but === checks for both type and value.

11.What kind of conditional statements does JavaScript support?

Ans:

•if statement

•if – else statement

•if – else if – else statement

•switch statement

12.What does “1”+2+4 evaluate to? What about 5 + 4 + “3”?

Ans:

Since 1 is a string, everything is a string, so the result is 124. In the second case, its 93.

13.Methods GET and POST in HTML forms - what's the difference?

Ans:

GET: Parameters are passed in the query string. Maximum amount of data that can be sent via the
GET method is limited to about 2kb.

POST: Parameters are passed in the request body. There is no limit to the amount of data that can be
transferred using POST. However, there are limits on the maximum amount of data that can be
transferred in one name/value pair.

14.Is a JavaScript script faster than an ASP script?

Ans:

Yes. Since JavaScript is a client-side script it does require the web server's help for its computation, so
it is always faster than any server-side script like ASP, PHP, etc.

15.Does JavaScript have the concept level scope?

Ans:
No. Javascript does not have block level scope, all the variables declared inside a function possess
the same level of scope unlike c, c++, java.

16.What is this keyword?

Ans:

In JavaScript this keywork refers to the current object.

17.What can JavaScript programs do?

Ans:

 Generation of HTML pages on-the-fly without accessing the Web server.

 The user can be given control over the browser like User input validation Simple
computations can be performed on the client's machine The user's browser, OS, screen size,
etc.

 can be detected Date and Time Handling

18.What does undefined value mean in JavaScript?

Ans:

Undefined value means the variable used in the code doesn't exist or is not assigned any value or the
property doesn't exist

19.What is the difference between undefined value and null value?

Ans:

(i) Undefined value cannot be explicitly stated that is there is no keyword called undefined whereas
null value has keyword called null

(ii) typeof undefined variable or property returns undefined whereas typeof null value returns
object

20.What is variable typing in JavaScript?

Ans:

It is perfectly legal to assign a number to a variable and then assign a string to the same variable as
follows

example

i = 10;

i = "string";

This is called variable typing

21.What are undefined and undeclared variables?


Ans:

 Undeclared variables are those that are not declared in the program (do not exist at all),
trying to read their values gives runtime error.But if undeclared variables are assigned then
implicit declaration is done .

 Undefined variables are those that are not assigned any value but are declared in the
program. Trying to read such variables gives special value called undefined value.

22.What is === operator?

Ans:

In JavaScript === is strict equality operator ,it returns true only when the two operands are having
the same value without any type conversion.

23.How to disable an HTML object?

Ans:

To disable an HTML object in JavaScript use below line of code...

document.getElementById("myObject").disabled = true;

24.To write messages to the screen without using "document.write()"?

Ans:

Changing the contents of an element is a much better solution. When the method showStatus is
invoked it will change the content of the span.

function showStatus(message) {

var element = document.getElementById("mystatus");

element.textContent = message; //for Firefox

element.innerHTML = message; //for IE (why can't we all just get along?)

return true;

< span id="mystatus" > Test. < /span >

25.How to create a popup warning box?

Ans:

Below line will help us how to create a popup warning box in JavaScript....

alert('Warning: Please enter an integer between 0 and 100.');

26.How to create a confirmation box?

Ans:
Below line will help us how to create a Confirmation box in JavaScript....

confirm("Do you really want to launch the missile today. HuM?");

27.How to create an input box?

Ans:

Below line will help us how to create a Input box in JavaScript....

prompt("What is your name?");

28.How to change style on an element?

Ans:

Between CSS and JavaScript is a weird symmetry. CSS style rules are laid on top of the DOM. The CSS
property names like "font-weight" are transliterated into "myElement.style.fontWeight". The class of
an element can be swapped out. For example:

document.getElementById("myText").style.color = "green";

document.getElementById("myText").style.fontSize = "20";

-or-

document.getElementById("myText").className = "regular";

29.How to make elements invisible?

Ans:

Change the "visibility" attribute of the style object associated with your element. Remember that a
hidden element still takes up space, use "display" to make the space disappear as well.

if ( x == y) {

myElement.style.visibility = 'visible';

} else {

myElement.style.visibility = 'hidden';

30.How to set the cursor to wait?

Ans:

In theory, we should cache the current state of the cursor and then put it back to its original state.

document.body.style.cursor = 'wait';

//do something interesting and time consuming

document.body.style.cursor = 'auto';

31.How to force a page to go to another page using JavaScript?


Ans:

< script language="JavaScript" type="text/javascript" >

< !--

location.href="http://www.globalguideline.com";

//-- >

< /script >

32.How to convert a string to a number using JavaScript?

Ans:

We can use the parseInt() and parseFloat() methods in JavaScript to convert a string to a number or
numeric value. Notice that extra letters following a valid number are ignored, which is kinda wierd
but convenient at times.

parseInt("100") ==> 100

parseFloat("98.6") ==> 98.6

parseFloat("98.6 is a common temperature.") ==> 98.6

parseInt("aa") ==> Nan //Not a Number

parseInt("aa",16) ==> 170 //We can supply a radix or base

33.How to convert numbers to strings using JavaScript?

Ans:

We can prepend the number with an empty string in JavaScript

var mystring = ""+myinteger;

//or

var mystring = myinteger.toString();

We can specify a base for the conversion,

var myinteger = 14;

var mystring = myinteger.toString(16);

mystring will be "e".

34.What's the Date object using JavaScript?

Ans:

Time inside a date object is stored as milliseconds since Jan 1, 1970 in JavaScript.

e.g.
new Date(06,01,02) // produces "Fri Feb 02 1906 00:00:00 GMT-0600 (Central Standard Time)"

new Date(06,01,02).toLocaleString() // produces "Friday, February 02, 1906 00:00:00"

new Date(06,01,02) - new Date(06,01,01) // produces "86400000"

35.What's Math Constants and Functions using JavaScript?

Ans:

The Math object contains useful constants such as

Math.PI, Math.E

Math also has a zillion helpful functions in JavaScript.

Math.abs(value); //absolute value

Math.max(value1, value2); //find the largest

Math.random() //generate a decimal number between 0 and 1

Math.floor(Math.random()*101) //generate a decimal number between 0 and 100

36.What does the delete operator do?

Ans:

The delete operator is used to delete all the variables and objects used in the program ,but it does
not delete variables declared with var keyword.

37.How to create a function using function constructor?

Ans:

The following example illustrates this

It creates a function called square with argument x and returns x multiplied by itself.

var square = new Function ("x","return x*x");

38.How do you submit a form using JavaScript?

Ans:

Use document.forms[0].submit()

(0 refers to the index of the form – if we have more than one form in a page, then the first one has
the index 0, second has index 1 and so on).

39.How to read and write a file using JavaScript?

Ans:

I/O operations like reading or writing a file is not possible with client-side JavaScript. However , this
can be done by coding a Java applet that reads files for the script

40.How to detect the operating system on the client machine?


Ans:

In order to detect the operating system on the client machine, the navigator.appVersion string
(property) should be used.

41.Where are cookies actually stored on the hard disk?

Ans:

This depends on the user's browser and OS.

In the case of Netscape with Windows OS, all the cookies are stored in a single file called

cookies.txt

c:Program FilesNetscapeUsersusernamecookies.txt

In the case of IE,each cookie is stored in a separate file namely username@website.txt.

c:WindowsCookiesusername@Website.txt

42.How to set a HTML document's background color?

Ans:

document.bgcolor property can be set to any appropriate color.

43.How to embed JavaScript in a web page?

Ans: JavaScript code can be embedded in a web page between

< script langugage="javascript" >

//Place Your JavaScript here.

< /script >

44.What Boolean operators does JavaScript support?

Ans:

Boolean operators in JavaScript are as under

&&, || and !

45.How to get the contents of an input box using JavaScript?

Ans:

Use the "value" property.

var myValue = window.document.getElementById("MyTextBox").value;

46.How to determine the state of a checkbox using JavaScript?

Ans:

Determining the state of a checkbox in JavaScript


var checkedP = window.document.getElementById("myCheckBox").checked;

47.How to access an external JavaScript file that is stored externally and not embedded?

Ans: This can be achieved by using the following tag between head tags or between body tags.

< script src="abc.js" > < /script >

How to access an external JavaScript file that is stored externally and not embedded? where abc.js is
the external JavaScript file to be accessed.

48.What is Javascript namespacing? How and where is it used?

Ans:

 Using global variables in Javascript is evil and a bad practice.

 That being said, namespacing is used to bundle up all your functionality using a unique
name.

 In JavaScript, a namespace is really just an object that you’ve attached all further methods,
properties and objects.

 It promotes modularity and code reuse in the application.

You might also like