Friday 10 April 2015

jQuery Interview Questions And Answers.

1. What is jQuery?

Ans: jQuery is fast, lightweight and feature-rich client side JavaScript Library/Framework which helps in to traverse HTML DOM, make animations, add Ajax interaction, manipulate the page content, change the style and provide cool UI effect. It is one of the most popular client side library.

2. Why do we use jQuery?

Ans: Due to following advantages.
Easy to use and learn.
Easily expandable.
Cross-browser support (IE 6.0+, FF 1.5+, Safari 2.0+, Opera 9.0+)
Easy to use for DOM manipulation.
AJAX Capabilities.
Methods for changing or applying CSS, creating animations.
Event detection and handling.

3. How JavaScript and jQuery are different?

Ans: JavaScript is a language While jQuery is a library built in the JavaScript language.

4. Is jQuery replacement of Java Script?

Ans: No. jQuery is not a replacement of JavaScript. jQuery is a different library which is written on top of JavaScript. jQuery is a lightweight JavaScript library that emphasizes interaction between JavaScript and HTML.

5. Is jQuery a W3C standard?

Ans: No. jQuery is not a W3C standard.

6. What does dollar sign ($) means in jQuery?

Ans: Dollar Sign is nothing but it's an alias for JQuery. Take a look at below jQuery code.
$(document).ready(function(){
});
Over here $ sign can be replaced with "jQuery" keyword.
jQuery(document).ready(function(){
});

7. Can we have multiple document.ready() function on the same page?

Ans: YES. We can have any number of document.ready() function on the same page.

8. Can we use our own specific character in the place of $ sign in jQuery?

Ans: Yes. It is possible using jQuery.noConflict().
var $j = jQuery.noConflict();
// Use jQuery via jQuery(...)
$j(document).ready(function(){
   $j("div").hide();
});

9. Is there any difference between body onload() and document.ready() function?

Ans: document.ready() function is different from body onload() function for 2 reasons.
We can have more than one document.ready() function in a page where we can have only one body onload function.
document.ready() function is called as soon as DOM is loaded where body.onload() function is called when everything gets loaded on the page that includes DOM, images and all associated resources of the page.

10. What is a CDN?

Ans: A content delivery network or content distribution network (CDN) is a large distributed system of servers deployed in multiple data centers across the Internet. The goal of a CDN is to serve content to end-users with high availability and high performance.
There are 3 popular jQuery CDNs.
1. Google.
2. Microsoft
3. jQuery.

11. What are selectors in jQuery and how many types of selectors are there?

Ans: To work with an element on the web page, first we need to find them. To find the html element in jQuery we use selectors. There are many types of selectors but basic selectors are:

Name: Selects all elements which match with the given element Name.
#ID: Selects a single element which matches with the given ID
.Class: Selects all elements which match with the given Class.
Universal (*): Selects all elements available in a DOM.
Multiple Elements E, F, G: Selects the combined results of all the specified selectors E, F or G.
Attribute Selector: Select elements based on its attribute value.

12. What are the fastest selectors in jQuery?

Ans: ID and element selectors are the fastest selectors in jQuery.

13. What are the slow selectors in jQuery?

Ans: class selectors are the slow compare to ID and element.

14. Which is fast document.getElementByID('txtName') or $('#txtName').?

Ans: Native JavaScipt is always fast. jQuery method to select txtName "$('#txtName')" will internally makes a call to document.getElementByID('txtName'). As jQuery is written on top of JavaScript and it internally uses JavaScript only So JavaScript is always fast.

15. Difference between $(this) and 'this' in jQuery?

Ans: this and $(this) refers to the same element. The only difference is the way they are used. 'this' is used in traditional sense, when 'this' is wrapped in $() then it becomes a jQuery object and you are able to use the power of jQuery.
$(document).ready(function(){
    $('#spnValue').mouseover(function(){
       alert($(this).text());
  });
});
In below example, this is an object but since it is not wrapped in $(), we can't use jQuery method and use the native JavaScript to get the value of span element.
$(document).ready(function(){
    $('#spnValue').mouseover(function(){
       alert(this.innerText);
  });
});

16. How do you check if an element exists or not in jQuery? 

Ans: Using jQuery length property, we can ensure whether element exists or not.
$(document).ready(function(){
    if ($('#element').length > 0){
       //Element exists
  }
});

17. How do you check if an element is empty?

Ans: There are 2 ways to check if element is empty or not. We can check using ":empty" selector.
$(document).ready(function(){
    if ($('#element').is(':empty')){
       //Element is empty
  }
});
And the second way is using the "$.trim()" method.
$(document).ready(function(){
    if($.trim($('#element').html())=='') {
       //Element is empty
  }
});

18. What is the difference between jquery.size() and jquery.length?

Ans: jQuery .size() method returns number of element in the object. But it is not preferred to use the size() method as jQuery provide .length property and which does the same thing. But the .length property is preferred because it does not have the overhead of a function call.

19. What is the difference between $('div') and $('<div/>') in jQuery?

Ans: $('<div/>') : This creates a new div element. However this is not added to DOM tree unless you don't append it to any DOM element.
$('div') : This selects all the div element present on the page.

20. What is the difference between parent() and parents() methods in jQuery?

Ans: The basic difference is the parent() function travels only one level in the DOM tree, where parents() function search through the whole DOM tree.

21. What is the difference between .empty(), .remove() and .detach() methods in jQuery?

Ans: All these methods .empty(), .remove() and .detach() are used for removing elements from DOM but they all are different.

.empty(): This method removes all the child element of the matched element where remove() method removes set of matched elements from DOM.

.remove(): Use .remove() when you want to remove the element itself, as well as everything inside it. In addition to the elements themselves, all bound events and jQuery data associated with the elements are removed.

.detach(): This method is the same as .remove(), except that .detach() keeps all jQuery data associated with the removed elements. This method is useful when removed elements are to be reinserted into the DOM at a later time.

22. Explain .bind() vs .live() vs .delegate() vs .on()

Ans: All these 4 jQuery methods are used for attaching events to selectors or elements. But they all are different from each other.

.bind(): This is the easiest and quick method to bind events. But the issue with bind() is that it doesn't work for elements added dynamically that matches the same selector. bind() only attach events to the current elements not future element. Above that it also has performance issues when dealing with a large selection.

.live(): This method overcomes the disadvantage of bind(). It works for dynamically added elements or future elements. Because of its poor performance on large pages, this method is deprecated as of jQuery 1.7 and you should stop using it. Chaining is not properly supported using this method.

.delegate(): The .delegate() method behaves in a similar fashion to the .live() method, but instead of attaching the selector/event information to the document, you can choose where it is anchored and it also supports chaining.

.on(): Since live was deprecated with 1.7, so new method was introduced named ".on()". This method provides all the goodness of previous 3 methods and it brings uniformity for attaching event handlers.

23. What is event.PreventDefault?

Ans: The event.preventDefault() method stops the default action of an element from happening. For example, Prevents a link from following the URL.

24. What is the difference between event.PreventDefault and event.stopPropagation?

Ans: event.preventDefault(): Stops the default action of an element from happening.
event.stopPropagation(): Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event. For example, if there is a link with a click method attached inside of a DIV or FORM that also has a click method attached, it will prevent the DIV or FORM click method from firing.

25. Can you include multiple version of jQuery? If yes, then how they are executed?

Ans: Yes. Multiple versions of jQuery can be included in same page.

26. In what situation you would use multiple version of jQuery and how would you include them?

Ans: Well, it is quite possible that the jQuery plugins which are used are dependent on older version but for your own jQuery code, you would like to use newer version. So because of this dependency, multiple version of jQuery may required sometimes on single page.
Below code shows how to include multiple version of jQuery.
<script type='text/javascript' src='js/jquery_1.9.1.min.js'></script>
<script type='text/javascript'>
 var $jq = jQuery.noConflict();
</script>
<script type='text/javascript' src='js/jquery_1.7.2.min.js'></script>
By this way, for your own jQuery code use "$jq", instead of "$" as "$jq" refers to jQuery 1.9.1, where "$" refers to 1.7.2.

27. What is chaining in jQuery?

Ans: Chaining is one of the most powerful feature of jQuery. In jQuery, Chaining means to connect multiple functions, events on selectors. It makes your code short and easy to manage and it gives better performance. The chain starts from left to right. So left most will be called first and so on.
The above jQuery code sample can be re-written using chaining. See below.
​$(document).ready(function(){
    $('#dvContent').addClass('dummy').css('color', 'red').fadeIn('slow');  
});​

28. How to write browser specific code using jQuery?

Ans: Using jQuery.browser property, we can write browser specific code. This property contains flags for the useragent, read from navigator.userAgent. This property was removed in jQuery 1.9.

29. Can we use jQuery to make ajax request?

Ans: Yes. jQuery can be used for making ajax request.

30. What are various methods to make ajax request in jQuery?

Ans: Using below jQuery methods, you can make ajax calls.
load() : Load a piece of html into a container DOM
$.getJSON(): Load JSON with GET method.
$.getScript(): Load a JavaScript file.
$.get(): Use to make a GET call and play extensively with the response.
$.post(): Use to make a POST call and don't want to load the response to some container DOM.
$.ajax(): Use this to do something on XHR failures, or to specify ajax options (e.g. cache: true) on the fly.

31. Is there any advantage of using $.ajax() for ajax call against $.get() or $.post()?

Ans: By using jQuery post()/ jQuery get(), you always trust the response from the server and you believe it is going to be successful all the time. Well, it is certainly not a good idea to trust the response. As there can be n number of reason which may lead to failure of response.

Where jQuery.ajax() is jQuery's low-level AJAX implementation. $.get and $.post are higher-level abstractions that are often easier to understand and use, but don't offer as much functionality (such as error callbacks).

32. How can we debug jQuery?

There are two ways to debug jQuery:
Debugger keyword
Add the debugger to the line from where we have to start debugging and then run Visual Studio in Debug mode with F5 function key.
Insert a break point after attaching the process

33. What are deferred and promise object in jQuery?

Ans: Deferred and promise are part of jQuery since version 1.5 and they help in handling asynchronous functions like Ajax.






Thursday 9 April 2015

CSS Interview Questions And Answers

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

Ans: There are three ways to include css in our html page or web page.
Inline CSS
syntax: <div style="color:red;">some text here</div>
Internal CSS
Syntax: <style>
.selecter{
color:red // we can write any properties
}
</style>
External CSS
Syntax: <link rel="stylesheet" type="text/css" href="style.css">

2. If we have same css property for inline and interanl which one will apply?

Ans: inline css property is giving more priority. so inline css propery will applay
     priority order inline css -> internal css -> external css

3. What is an !important CSS?

Ans: if we write somthing like p{color:red}, p{color:blue !important};
      paragraph(p) will take the blue color.
      we are explicitly saying take the specipic property
      And also we can change the priority of Question 2

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

h1, h2, h3 {background: red;}

7. What are selectors in CSS?

Ans: Selectors help to select an element to which you want to apply a style.
    example: class, id, tags (p,h1, h6,<div> <span>) ;

8. What is block level element and inline element?

Ans: A block element is an element that takes up the full width available, and has a line break before and after it. <h1>, <p>, <li>, and <div> are all examples of block elements.
An inline element only takes up as much width as necessary, cannot accept width and height values, and does not force line breaks. <a> and <span> are examples of inline elements.

9.  Explain the difference between visibility:hidden and display:none.

Ans: visibility:hidden simply hides the element, while it will still take up space and affect the layout of the document.
display:none also hides the element, but will not take up space and the page will appear as if the element is not present.

10. What are some of the new features and properties in CSS3?

Ans: Box model
New Web fonts
Rounded corners
Border Images
Box Shadows, Text Shadows
New Color schemes (RGBA)
Transform property
New Pseudo-classes
Multi-column layout
New Gradients

11. What is an ID selector?

Ans: 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.
#example1: {background: blue;}
<p id="selector">...</p>

12. What is a class?

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.
.classexample {font-family: Helvetica; font-size: 20; background: black;}
<div class="classexample">....</div>

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

14. 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;}
classname1 classname2 { color:red};
classname2 is child class.

15. 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;}
p:nth-child(number){
color:red;
}

15. 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;}
p:nth-child(number){
color:red;
}

16. What are Sass, LESS, and Stylus? Why do people use them? How does something like Compass relate to Sass?

 Ans: They are CSS preprocessors. They are an abstraction layer on top of CSS. They are a special syntax/language that compile down into CSS. They make managing CSS easier, with things like variables and mixins to handle vendor prefixes (among other things). They make doing best practices easier, like concatenating and compressing CSS.

 17. Describe what a “reset” CSS file does and how it’s useful. Are you familiar with normalize.css? Do you understand how they differ?

 Ans: Resets are so wildly common in CSS that anyone who is a front end developer type has surely used them. Do they do so blindly or do they know why? The reason is essentially that different browsers have different default styling for elements, and if you don't deal with that at all, you risk designers looking unnecessarily different in different browsers and possibly more dramatic breaking problems.

Normalize you might call a CSS reset alternative. Instead of wiping out all styles, it delivers a set of reasonable defaults. It doesn't unset things that are already consistent across browsers and reasonable (e.g. bold headers). In that way it does some less than a reset. It also does some more than a reset in that it handles quirks you may never consider, like HTML5 audio element inconsistencies or line-height inconsistencies when you use sub and sup elements.

18. What is responsive design all about?

Ans: It's about making websites work wherever the web is. Different devices with different sizes and different capabilities. Responsive design is about taking one code base and making it work for all of them. Part of that is media queries and different visuals. Part of that is different resources (e.g. different JavaScript to handle touch vs click or different images to accommodate the screen).

19. What are the various techniques for clearing floats?

Ans: Floats are still incredibly common. As this is published, still probably the most cross-browser consistent way to build layout and grids. Anyone who has worked with them is aware of float collapsing. That is, floated element do not add to the height of a parent element. So for example if a parent element contained only floated elements, it would collapse to zero height. You can deal with that like:


Use a clearfix (bonus points for micro clearfix).
Float the parent as well.
Use an overflow property other than "visible" on the parent (bonus points for listing downsides like cutting off shadows).
Bonus points for "create a new block formatting context". Possibly negative points for something like <br style="clear: both;">

20. What is Box model ?

Ans: CSS box model is made up of margins, borders, padding, and content.
Box model provides a structured way to space elements in relationship to each other.
Padding: inside the cell spacing.
padding has 4 properties
padding-right :10px,padding-bottom :10px,padding-left :10px, padding-top :10px,
sorform of padding:
padding: 10 10 20 10;

margin : want to move the box(div) from outside we need to use margin
margin also having 4 properties like padding
margin:10 10 4 4;

Border: - This defines the maximum area in which the element will be contained. We can make the border visible, invisible, define height and width etc.


21. What are sprites and why would use them? How do you go about creating them? What are possible alternatives to sprites?

Sprites are essentially multiple images combined into one. Performance is the reason that they are used.




HTML 5 interview Questions And Answers

1. What is the difference between HTML and HTML5 ?

Ans: HTML5 is nothing more then upgraded version of HTML where in HTML5 supports the innovative features such as Video, Audio/mp3, date select function , placeholder , Canvas, 2D/3D Graphics, Local SQL Database added some nwe tags <header></header>, <footer></footer>, <artical></artical>, <section></section>,<nav></nav>, <time></time> etc..


2. What are the different new form element types in HTML 5?

Ans: There are some important new form elements introduced in HTML 5:-
   Ex:Color.
 Date
 Datetime-local
 Email
 Time
 Url
 Range
 Telephone
 Number
 Search

3. WHAT are some other advantages of HTML5?

 a) Cleaner markup than earlier versions of HTML
 b) Additional semantics of new elements like <header>, <nav>, and <time>
 c) New form input types such as 
   Ex:Color.
 Date
 Datetime-local
 Email
 Time
 Url
 Range
 Telephone
 Number
 Search

4. What is the use of Canvas Element in HTML5? 

Ans: HTML5 Canvas element can be used to draw graphics images on a web page by using javascript.
Ex:<canvas id=“myCanvas” width=“500″ height=“400″></canvas>
 <script type=“text/javascript”>
 var myCanvas=document.getElementById(“myCanvas”);
 var myText=myCanvas.getContext(“2d”);
 myText.fillStyle=“#82345c”;
 myText.fillRect(0,0,150,75);
 </script>

5. If I do not put <! DOCTYPE html> will HTML 5 work?

Ans: No, browser will not be able to identify that it’s a HTML document and HTML 5 tags will not function properly.

6. Which browsers support HTML 5?

Ans: Almost all browsers i.e. Safari, Chrome, Firefox, Opera, Internet Explorer support HTML 5.


7. What is SVG?

Ans: SVG stands for scalable vector graphics. It’s a text based graphic language which draws images using text, lines, dots etc. This makes it lightweight and renders faster.
Ex: <svg id="svgelem" height="[object SVGAnimatedLength]" xmlns="http://www.w3.org/2000/svg">
 <line style="stroke: rgb(255, 0, 0); stroke-width: 2px;" y2="[object SVGAnimatedLength]" x2="[object SVGAnimatedLength]" y1="[object SVGAnimatedLength]" x1="[object SVGAnimatedLength]">
 </line>

8. What is the major improvement with HTML5 in reference to Flash?

Ans:  Flash is not supported by major mobile devices such as iPad, iPhone and universal android applications. Those mobile devices have lack of support for installing flash plugins. HTML5 is supported by all the devices, apps and browser including Apple and Android products. Compared to Flash, HTML5 is very secured and protected. That eliminates major concerns that we have seen with Flash.

9. What is the sessionStorage Object in html5 ? How you can create and access that?

Ans: The HTML5 sessionStorage object stores the data for one session. The data is deleted when the user closes the browser window. We can create and access a sessionStorage, created “name” as session
Ex: <script type=“text/javascript”>
 sessionStorage.name=“bujji”;
 document.write(sessionStorage.name);
 </script>

10. What is HTML5 Web Storage? Explain localStorage and sessionStorage.?

Ans: With HTML5, web pages can store data locally within the user’s browser.
 Earlier, this was done with cookies. However, Web Storage is more secure and faster. The data is not included with every server request, but used ONLY when asked for.

 The data is stored in name/value pairs, and a web page can only access data stored by itself. Unlike cookies, the storage limit is far larger (at least 5MB) and information is never transferred to the server.

 The difference between localStorage and sessionStorage involves the lifetime and scope of the storage.
 Data stored through localStorage is permanent: it does not expire and remains stored on the user’s computer until a web app deletes it or the user asks the browser to delete it. 

SessionStorage has the same lifetime as the top-level window or browser tab in which the script that stored it is running. When the window or tab is permanently closed, any data stored through sessionStorage is deleted.

 Both forms of storage are scoped to the document origin so that documents with different origins will never share the stored objects. But sessionStorage is also scoped on a per-window basis. If a user has two browser tabs displaying documents from the same origin, those two tabs have separate sessionStorage data: the scripts running in one tab cannot read or overwrite the data written by scripts in the other tab, even if both tabs are visiting exactly the same page and are running exactly the same scripts.

11. What are the Video And Audio tags?

Ans:    <video src="http://www.example.com/amazing_video.mp4" width="640" height="360" controls></video>
    another way:
    <video width="640" height="360" controls>
    <source src="http://www.example.com/amazing_video.mp4">
    </video>

12. What are some of the key new features in HTML5?

Ans: Key new features of HTML5 include:
 Improved support for embedding graphics, audio, and video content via the new <canvas>, <audio>, and <video> tags.
 Extensions to the JavaScript API such as geolocation and drag-and-drop as well for storage and caching
 Introduction of “web workers”.
 Several new semantic tags were also added to complement the structural logic of modern web applications. These include the <main>, <nav>, <article>, <section>, <header>, <footer>, and <aside> tags.
 New form controls, such as <calendar>, <date>, <time>, <email>, <url>, and <search>.

13. What are “web workers”?

Ans: Web workers at long last bring multi-threading to JavaScript.
A web worker is a script that runs in the background (i.e., in another thread) without the page needing to wait for it to complete. The user can continue to interact with the page while the web worker runs in the background. Workers utilize thread-like message passing to achieve parallelism.

JavaScript Interview Questions And Answers.

1. What is JavaScript?

Ans: JavaScript is a scripting language most often used for client-side web development.

2. What are JavaScript types?

Ans: a) Number
b) String
c) Boolean
d) Function
e) Object
f) Null
g) Undefined

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

Ans: == is compre the values and === is compre the values as well as type.
ex: var x="4";
            var y=4;

           x==y returns true;
          x===y treturns false;

4. What are the way of make comment in Javascript?

Ans: There are 2 types of comments in javascript
      a) single line comment.( ex: // your code ).
      b) multiline comment (ex: /* your code
  morethen one line */)

5. How you will get the CheckBox status whether it is checked or not?

Ans: var status = document.getElementById('checkbox1').checked;
alert(status);
it will return true or false.

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

Ans: Since 1 is a string, everything is a string, so the result is 124. string+integer is string

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

Ans: step1: 1+2 is 3
       step2: 3+"4"
       result is 34 because integer + string returns string.

8. How do you change the style/class on any element using javascript?

Ans: document.getElementById(“myText”).style.fontSize = “10";
-or-
document.getElementById(“myText”).className = “anyclass”;

9. What is ‘this’ keyword in JavaScript?

Ans: 'this' is a keyword used to point the corrent object in the code .

10. What is the function of delete operator?

Ans: The functionality of delete operator is used to delete all variables and objects in a program but it          cannot delete
        variables declared with VAR keyword.

11. What is the use of Void(0)?

Ans: Void(0) is used to prevent the page from refreshing and parameter “zero” is passed while calling.
Void(0) is used to call another method without refreshing the page.

12. How to create arrays in JavaScript?

Ans:There are two ways to create array in JavaScript like other languages:
    a) The first way to create array
Declare Array:
EX:var names = new Array(); or var names = [];
Add Elements in Array:-
names[0] = “bujji”;
names[1] = “babu”;

  b) This is the second way:
var names = new Array("bujji", “babu”);

13) How do you submit a form using JavaScript? 
 
Ans: Use document.forms[0].submit();

14) What does isNaN function do?

Ans: It returns true if the argument is not a number.
     if argument is a number is return false

15.What is DOM? What is the use of document object?

Ans: DOM stands for Document Object Model. A document object represent the html document. It can be used to access and change the content of html.

16. What is the use of window object?

Ans: The window object is automatically created by the browser that represents a window of a browser.
    It is used to display the popup dialog box such as alert dialog box, confirm dialog box, input dialog box etc.
    Window is the object of browser, it is not the object of javascript.
   using window object we can modify the global variables.

17.What is the use of history object?

Ans: The history object of browser can be used to switch to history pages such as back and forward from current page or another page. There are three methods of history object.
    history.back()
    history.forward()
    history.go(number): number may be positive for forward, negative for backward.

18.Difference between ‘undefined’ and ‘null’

Ans:
    Undefined:
     In JavaScript, undefined is a variable with no value.
     The typeof a variable with no value is also undefined.
     ex: var x  //Value is undefined, type is undefined
    Null:
     In JavaScript null is "nothing". It is supposed to be something that doesn't exist.
     Unfortunately, in JavaScript, the data type of null is an object.
    ex: var y = null;   // Value is null, but type is still an object
 Note: x==y returns true;
       x===y returns false.

19.  what is javascript clouser? 

Ans:A closure is a function having access to the parent scope, even after the parent function has closed.
 Ex: var add = (function () {
    var counter = 0;
    return function () {return counter += 1;}
})();
add();
add();
add();

The variable add is assigned the return value of a self invoking function.
The self-invoking function only runs once. It sets the counter to zero (0), and returns a function expression.
This way add becomes a function. The "wonderful" part is that it can access the counter in the parent scope.
This is called a JavaScript closure. It makes it possible for a function to have "private" variables.
The counter is protected by the scope of the anonymous function, and can only be changed using the add function.