Monday, 17 March 2014

Interview Q & A on Javascript,Master Page and CSS in Asp.Net(Part 1)

JAVA Script


1.WhatisJavaScript?
JavaScript is a platform-independent,event-driven, interpreted client-side scripting language developed by Netscape Communications Corp. and Sun Microsystems.

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.

2. How is JavaScript different from Java?
Don't be fooled by the term Java in both. Both are quite different technologies.

JavaScript 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.

3. What is the official JavaScript website?
This is a trick question used by interviewers to evaluate the candidate’s knowledge of JavaScript. Most people will simply say javascript.com is the official website.

The truth is- there is no official website for Javascript you can refer to. It was developed by Brendan Eich for Netscape. It was based on the ECMAScript language standard; ECMA-262 being the official JavaScript standard.

5. What are the various datatypes in javascript?
Number
String
Boolean
Function
Object
Null
Undefined

6. What boolean operators does JavaScript support?

&&, || and !

7. What is negative infinity?

It’s a number in JavaScript, derived by dividing negative number by zero.

8. Is it possible to check if a variable is an object?

Yes, it is possible to do so. The following piece of code will help achieve the same.

If(abc&&typeofabc==="object")
{
 console.log('abc is an object and does not return null value');
   }

9. Can you explain what isNaN function does?

isNaN function will check an argument and return TRUE (1) if the argument does not seem to be a number.

10. How do you convert numbers between different bases in JavaScript?

Use the parseInt() function, that takes a string as the first parameter, and the base as a second parameter. So to convert hexadecimal 3F to decimal, use parseInt ("3F", 16);

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

undefined means a variable has been declared but has not yet been assigned a value. On the other hand, null is an assignment value. It can be assigned to a variable as a representation of no value.

Also, undefined and null are two distinct types: undefined is a type itself (undefined) while null is an object.
Unassigned variables are initialized by JavaScript with a default value of undefined. JavaScript never sets a value to null. That must be done programmatically.

12. What is the difference between “==” and “===”?

While “==” checks only for equality, “===” checks for equality as well as the type.

13. Differentiate between “var a=2” and “a =2”

The major difference between the two is that one variable is local and the other is global. “var” basically defines the scope of the variable.

When we add var to a variable value assignment, javascript ensures that the variable is confined to whichever function it is assigned to and does not collide with the same name variable within another function.

When we don’t use var, then it is declared as a global function and chances of collision can happen. So it’s always advisable to use “var” before variable value assignment. If needed use an anonymous function for closure.

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

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.

15. What does "1"+2+4 evaluate to?

Since 1 is a string, everything is a string, so the result is 124.

16. How about 2+5+"8"?

Since 2 and 5 are integers, this is number arithmetic, since 8 is a string, it’s concatenation, so 78 is the result.

17. How to create arrays in JavaScript?

We can declare an array like this
var scripts = new Array();
We can add elements to this array like this

scripts[0] = "PHP";
scripts[1] = "ASP";
scripts[2] = "JavaScript";
scripts[3] = "HTML";

Now our array scrips has 4 elements inside it and we can print or access them by using their index number. Note that index number starts from 0. To get the third element of the array we have to use the index number 2 . Here is the way to get the third element of an array.
document.write(scripts[2]);
We also can create an array like this
var no_array = new Array(21, 22, 23, 24, 25);
 
18. How do you create a new object in JavaScript?

var obj = new Object(); or var obj = {};

19. How do you assign object properties?

obj["age"] = 17 or obj.age = 17

20. What’s a way to append a value to an array?

arr[arr.length] = value;

21. What is this keyword?

It refers to the current object.
 
22. How many looping structures can you find in javascript?

If you are a programmer, you know the use of loops. It is used to run a piece of code multiple times according to some particular condition. Javascript being a popular scripting language supports the following loops

for
while
do-while loop

23. Are javascript and jQuery different?

jQuery is a quick as well as concise JavaScript Library that simplifies HTML document traversing, animating, event handling, & Ajax interactions for the purpose of quick web development needs. So although they are not entirely different, both are not the same either!

25. Is it possible for you to write a one line JavaScript code that concatenates all strings passed into a function?

The following function should help in producing the desired result

function concatenate()
{
  return String.prototype.concat.apply('', arguments);
}

26. Explain Javascript closures.

A basic overview of javascript closures is that it is a stack-frame which is not de-allocated when the function returns.

28. Difference between window.onload and onDocumentReady?

The onload event does not fire until every last piece of the page is loaded, this includes css and images, which means there’s a huge delay before any code is executed.

That isnt what we want. We just want to wait until the DOM is loaded and is able to be manipulated. onDocumentReady allows the programmer to do that.
 
29. How do you change the style/class on any element?

document.getElementById(“myText”).style.fontSize = “20″;
-or-
document.getElementById(“myText”).className = “anyclass”;

30. How is form submission possible via javascript?

We can achieve the desired form submission by using the function
 document.forms[0].submit().

It must be noted that the 0 in the piece of code given above refers to the form index. Say we have multiple forms on a particular page. To make all the form procession unique, we give each form index numbers. The first form will have the index number as 0. The second form will have an incremented number, 1. The third will have 2 and so on.

32. How to get CheckBox status whether it is checked or not?

alert(document.getElementById('checkbox1').checked);

if it will be checked you will get true else false.

33. How to get value from a textbox?

alert(document.getElementById('txtbox1').value);

34. How to get value from dropdown (select) control?

alert(document.getElementById('dropdown1').value);

35. How to get value from RadioButtonList control?

Here id is the name property of the RadioButtonList
function GetRadioButtonValue(id)
 {
 var radio = document.getElementsByName(id);
  for (var ii = 0; ii < radio.length; ii++)
 {
   if (radio[ii].checked)
  alert(radio[ii].value);
  }
  }

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

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


1.How does a content page differ from a master page?

A content page does not have complete HTML source code; whereas a master page has complete HTML source code inside its source file.

2.   What are Master Pages in ASP.NET? or What is a Master Page?

ASP.NET master pages allow you to create a consistent layout for the pages in your application. A single master page defines the look and feel and standard behavior that you want for all of the pages (or a group of pages) in your application. You can then create individual content pages that contain the content you want to display. When users request the content pages, they merge with the master page to produce output that combines the layout of the master page with the content from the content page.

3.   How do you identify a Master Page?

 The master page is identified by a special @ Master directive that replaces the @ Page directive that is used for ordinary .aspx pages.

4.    What is a ContentPlaceHolder?

ContentPlaceHolder is a region where replaceable content will appear.

5.   How do you bind a Content Page to a Master Page?

MasterPageFile attribute of a content page's @ Page directive is used to bind a Content Page to a Master Page.

9.   What are the advantages of using Master Pages?

1. They allow you to centralize the common functionality of your pages so that you can make updates in just one place.
2. They make it easy to create one set of controls and code and apply the results to a set of pages. For example, you can use controls on the master page to create a menu that applies to all pages.
3. They give you fine-grained control over the layout of the final page by allowing you to control how the placeholder controls are rendered.
4. They provide an object model that allows you to customize the master page from individual content pages.

10.       What are the 3 levels at which content pages can be attached to Master Page?

At the page level - You can use a page directive in each content page to bind it to a master page

At the application level - By making a setting in the pages element of the application's configuration file (Web.config), you can specify that all ASP.NET pages (.aspx files) in the application automatically bind to a master page.

At the folder level - This strategy is like binding at the application level, except that you make the setting in a Web.config file in one folder only. The master-page bindings then apply to the ASP.NET pages in that folder.

11.               Are controls on the master page accessible to content page code?

Yes, controls on the master page are accessible to content page code.

12.               At what stage of page processing master page and content page are merged?

During the initialization stage of page processing, master page and content page are merged.

13.               Can you dynaimically assign a Master Page?

Yes, you can assign a master page dynamically during the PreInit stage using the Page class MasterPageFile property as shown in the code sample below.
void Page_PreInit(Object sender, EventArgs e)
{
this.MasterPageFile = "~/MasterPage.master";
}

14.               Can you access non public properties and non public methods of a master page inside a content page?

No, the properties and methods of a master page must be public in order to access them on the content page.

15.                From the content page code how can you reference a control on the master page?

Use the FindControl() method as shown in the code sample below.
void Page_Load()
{
// Gets a reference to a TextBox control inside
// a ContentPlaceHolder
ContentPlaceHolder ContPlaceHldr = (ContentPlaceHolder)Master.FindControl ("ContentPlaceHolder1");
if(ContPlaceHldr != null)
{
TextBox TxtBox = (TextBox)ContPlaceHldr.FindControl("TextBox1");
if(TxtBox != null)
{
TxtBox.Text = "TextBox Present!";
}
}
// Gets a reference to a Label control that not in
// a ContentPlaceHolder
Label Lbl = (Label)Master.FindControl("Label1");
if(Lbl != null)
{
Lbl.Text = "Lable Present";
}
}

16.                Can you access controls on the Master Page without using FindControl() method?

Yes, by casting the Master to your MasterPage as shown in the below code sample.
protected void Page_Load(object sender, EventArgs e)
{
MyMasterPage MMP = this.Master;
MMP.MyTextBox.Text = "Text Box Found";
}


    CSS
1.What is CSS?

  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.Explain external Style Sheet? How would you link to it?

-        External Style Sheet can be called as a template/document/file which contains style information and can be linked with more than one HTML documents.
-       
- Using this the entire site can be formatted and styles just by editing one file.
- The file is linked with HTML documents via the LINK element inside the HEAD element.
<HEAD > <LINK REL=STYLESHEET HREF="style.css" TYPE="text/css"> </HEAD>


.  Explain RWD.
- RWD is the abbreviation for Responsive web design.
- In this technique, the designed page is perfectly displayed on every screen size and device, be it desktop, mobile, laptop or any other device. You don’t need to create a different page for each device.

 3.What is the use of CSS sprites?

- A web page with large number of images takes a longer time to load. This is because each image separately sends out a http request.
- The concept of CSS sprite helps in reducing this loading time for a web page by combining various small images into one image. This reduces the numbers of http request and hence the loading time.
4.What are style sheet properties?
CSS Background
CSS Text
CSS Font
CSS Border
CSS Outline..............

5.List various font attributes used in style sheet?
font-style
font-variant
font-weight
font-size/line-height

6.What are different ways to apply styles to a Web page?

There are four ways to integrate CSS into a Web page (some consider items three and four the same):
1. Inline: HTML elements may have CSS applied to them via the STYLE attribute.
2. Embedded: CSS may be embedded in a Web page by placing the code in a STYLE element within the HEAD element.
3. Linked: CSS may be placed in an external file (a simple text file containing CSS) and linked via the link element.
4. Imported: Another way to utilize external CSS files via @import.

7.What is an ID selector?

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 name can contain characters a-z, A-Z, digits 0-9, period, hyphen, escaped characters, and so forth.
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;}
<p id="selector">...</p>

No comments:

Post a Comment