Sunday 17 May 2015

HTML Best Practices

1. Start with DOCTYPE
Bad :
<html>
   <body>
      -----
   </body>
</html>
Good:

<!DOCTYPE html>
<html>
   <body>
     -----
   </body>
</html>
It helps to read and render your markup correctly.

2. Write Standards-Compliant Markup:
don't use the id attributes multiple time
don't omit the closing tags.
close the html tags properly.
Bad :

<p id="intro">properly close  the <strong> Html </p> tags .</strong>
<p id="intro">don't  omit the closing tag.
Good:

<p class="intro">properly close  the <strong> Html </strong> tags </p>
<p class="intro">don't  omit the closing tag.</p>

3. Use proper semantic elements

Bad:
<span class="heading"><strong>Heading</span></strong>
<br><br>
 some paragraph
<br><br>
Good:

<h1>Heading</h1>
<p>some paragraph</p>


4. Specify MIME type

Bad:
<link href="/pdf" rel="alternate">
<link href="/css/style.css" rel="stylesheet">
Good:

<link href="/pdf" rel="alternate" type="application/pdf">
<link href="/css/style.css" rel="stylesheet" type="text/css">


5. Write character encoding
Bad:
<head>
  <title>HTML Best Practices</title>
</head>
Good:

<head>
  <meta charset="UTF-8">
  <title>HTML Best Practices</title>
</head>


6. Avoid div structural elements

Bad:
<div class="container">
  <div class="article">
    <div class="headline">Heading</div>
  </div>
</div>
Good:

<div class="container">
  <article>
    <h1>Heading</h1>
  </article>
</div>


7. Syntax Organized

Bad:
<Aside>
<h3>heading</h3>
<H5 HIDDEN='HIDDEN'>Sub heading</H5>
<img src=sample.png alt="company logo" />
<ul>
<li>list item1</li>
<li>list item2</li>
</ul>
</ASIDE>
Good:

<aside>
  <h3>heading</h3>
  <h5 hidden>Sub heading</h5>
  <img src="sample.png" alt="company logo">
  <ul>
    <li>list item1</li>
<li>list item2</li>
  </ul>
</aside>

8. Don't use Inline Styles

Bad:
<p style="color:red">sample paragraph</p>
Good:

<p class="intro">sample paragraph</p>
keep external css
.intro {
color:red;
}

9. Keep all external style sheets inside head tag

<head>
<title>My Favorites Kinds of Corn</title>
<link rel="stylesheet" type="text/css" media="screen" href="libstyles.css" />
<link rel="stylesheet" type="text/css" media="screen" href="custom.css" />
</head>
The primary benefit is that your pages will load faster.
putting stylesheets in the HEAD allows the page to render progressively
load lib css first.
  • Use a CSS Reset
  • Placing Javascript Files at the Bottom
  • validate html in w3c 
10. Use meaning full title tags.
The <title> tag helps make a web page more meaningful and search-engine friendly. For example, the text inside the <title> tag appears in Google’s search engine results page, as well as in the user’s web browser bar and tabs.
Ex: <title>Welcome To Web Developer's Library</title>

11. Use Descriptive Meta Tags
Meta tags make your web page more meaningful for user agents like search engine spiders.

it will give the whole summary about your webpage or blog.

12. Minify CSS and JS.
we can decrease the size of the file. it means we are removing unnecessary space and comments.

13. Use right elements in right place.

14. Should use alt tag for image

15. Use modular IE fixes.
You should use conditional comments to target IE.
Ex: <!--[if IE 7]>
<link rel="stylesheet" href="css/ie-7.css" media="all">
<![endif]-->

16. Use lower case markup.

17. Validate your code.

18. Write well formatted code.

19. CSS  Exteranal files load in head tag.

20. JS External files load in body tag.

21. Choose good editor to develop the code.

22. For Beginners don't use CSS frame work better use css.

23. Use class instead of id for css, because you are losing benefits of class.

Friday 15 May 2015

Stop writing For loops. Start using underscore

Underscore:

Underscore.js is a JavaScript library which provides utility functions for common programming tasks. It is comparable to features provided by Prototype.js and the Ruby language, but opts for a functional programming design instead of extending object prototypes.

Underscore consists of a little more than 100 functions, which fall under four main categories depending on the datatypes which they manipulate: functions for manipulating arrays, functions for manipulating objects, functions for manipulating both arrays and objects (the name of the category is "Collections") and functions for manipulating other functions. There are also two utility categories : "Utility" and "Chaining".

Example:
for example if we use javascript to achieve some functionality we need to write the  below loop
var i,result = [];
for(i = 0; i < myArray.length; i++) {
  var myObject = myArray[i];
  if(myObject.isAwesome === true) {
      result.push(myArray[i]);
  }
}

The same functionality i can achieve  with underscore.js without loop.

var result = _.filter(myArray, function(myObject) {
  return myObject.isAwesome === true;
})

Underscore Reference : (http://underscorejs.org/)

Thursday 14 May 2015

Hybrid Mobile App Frameworks

Ionic & Angular:

The beautiful, open source front-end SDK for developing hybrid mobile apps with HTML5.

Free and open source, Ionic offers a library of mobile-optimized HTML, CSS and JS components, gestures, and tools for building highly interactive apps. Built with Sass and optimized for AngularJS

Advantages:
  • Open-source and free (under a permissive MIT license)
  • Built around Angular (Ember and Backbone not supported)
  • iOS and Android support (currently only WebKit supported devices)
  • Ionic is built to perform and behave great on the latest mobile devices. With minimal DOM manipulation, zero jQuery
  • Heavily optimized for touch devices (Ionic is focused on building native/hybrid mobile apps rather than mobile websites.)
  • Great command line utility support (Cordova users will recognize the benefit)
  • Optional Sass support
  • Supports Cordova, PhoneGap, or Trigger.io
  • Over 500 custom designed font icons MIT licensed
Built on top of the popular AngularJS framework from Google, Ionic utilizes AngularJS to provide the application structure, while Ionic itself focuses on the user interface. In other words, we see a match between the power of Angular and the beauty of Ionic UI.

Ionic provides a set of Angular directives (custom HTML elements) for it’s own components, making it as easy to use the widgets as writing a line of HTML code. In addition to directives, Ionic uses Angular’s touch recognizers, view animation logic, HTML sanitation, and asynchronous communication.
Ionic reference : ( http://ionicframework.com/)


Mobile Angular UI :

Build HTML5 create interactive mobile apps with Bootstrap3 and Angular JS

Mobile Angular UI is a mobile UI framework just like Sencha Touch or jQuery Mobile. If you know Angular JS and Twitter Bootstrap you already know it!

Main features of Mobile AngularUI
  • Bootstrap 3
  • AngularJS
  • Mobile Angular UI provides essential mobile components that are missing in Bootstrap 3: switches, overlays, sidebars, scrollable areas, absolute positioned top and bottom navbars that don't bounce on scroll.
  • AngularJS modules such as angular-route, angular-touch and angular-animate
  • Mobile Angular UI doesn’t have any jQuery dependencies, all you need are some AngularJS directives to create awesome mobile user experiences.
  • FontAwesome Icons are included by default in place of Glyphicons.
Mobile Angular UI Reference : (http://mobileangularui.com/)


Cordova/Phonegap:

Apache Cordova is a platform for building native mobile applications using HTML, CSS and JavaScript

Apache Cordova is an open-source mobile development framework.

These apps are natively installed on iOS, Android, Windows Phone, Blackberry, Tizen, Firefox OS, and others, all leveraging HTML for the user interface, CSS for layout and styling, and JavaScript for interactivity, dynamism, and interaction with native-OS functionality.

When using the Cordova APIs, an app can be built without any native code (Java, Objective-C, etc) from the app developer

And because these JavaScript APIs are consistent across multiple device platforms and built on web standards, the app should be portable to other device platforms with minimal to no changes.

a mobile developer and want to extend an application across more than one platform, without having to re-implement it with each platform's language and tool set.

a web developer and want to deploy a web app that's packaged for distribution in various app store portals

a mobile developer interested in mixing native application components with a WebView (special browser window) that can access device-level APIs, or if you want to develop a plugin interface between native and WebView components.

Cordova reference Link : (https://cordova.apache.org/)




jQuery Mobile


jQuery Mobile is an HTML5-based user interface system designed to make responsive websites and apps

jQuery Mobile is the easiest way to build sites and apps that are accessible on all popular smartphone, tablet and desktop devices.

jQuery Mobile is HTML5 markup based framework (not like Ionic Framework or Sencha Touch) inonic and scncha touch are built to work only on web kit browsers but jquery Mobile will run on pretty much anything as long it supports HTML5 standard.

jQuery Mobile offers CSS-based enhancements for common user interface elements(like classes, grid layout, responsive grid, theme)

Advantages:
  • Most commonly use, which means a lot of 3rd party information
  • Extremely easy to use, HTML5 bases, just like App Framework
  • Good official documentation.
  • Support every HTML5 browser you can think which makes it good for a desktop and mobile use
  • Excellent theme support
  • Large number of 3rd party plugins 
DisAdvantages:
  •  JQuery mobile apps are slow on mobiles.
  • Avarage UI
  • Every JQuery mobile app appears as a duplicate of the other with no customization.
  • JQuery Mobile does not offer “out of box” MVC support.
  • JQuery mobile, when combined with other mobile frameworks, becomes even more time-consuming.


jQueryMobile reference : (http://api.jquerymobile.com/)

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.

Friday 6 March 2015

Angular Basics

General Features :
  • AngularJS is a JavaScript framework.
  • AngularJS is a efficient framework that can create Rich Internet Applications.
  • Client side  MVC frameWork. 
  • Applications written in AngularJS are cross-browser compliant.
  • SPA (Single Page Application)
  • Supported for Web and mobiles.
  • AngularJS is open source, completely free.
  • AngularJS is a framework to build large scale Apps.
  • High performance, and easyto-maintain web applications.


Core Features:
Screen Shot 2015-03-03 at 1.43.45 pm.png


Screen Shot 2015-03-03 at 1.51.42 pm.png






Two way Data-binding: It is the automatic synchronization of data between model   and view
Scope : scope is an object that refers to the application model. Every controller has an associated scope object. Scopes provide APIs ($watch) to observe model mutations.

Controller: These are JavaScript functions bound to a particular scope.


Services: AngularJS comes with several built-in services such as $http to make a XMLHttpRequests. These are singleton objects which are instantiated only once in app.

Filters: These select a subset of items from an array and returns a new array.

Directives:
Directives are markers on DOM elements such as elements, attributes, css, and more. These can be used to create custom HTML tags that serve as new, custom widgets. AngularJS has built-in directives such as ngBind, ngModel, etc.

  • Predefined Directives
Ex: ng-app(route directive), ng-bind, ng-show, ng-hide, ng-repeat, ng-if.
we can also write data-ng-bind, data-ng-show etc..
  • Custom Directives
ex: we can write our custom tags
<div directivename ></div> like attribute
<customdirectivename></customdirectivename> linke html tag.

Routing: It is concept of switching views.

Templates: These are the rendered view with information from the controller and model. These can be a single file (such as index.html) or multiple views in one page using partials.

MVC: Model View whatever ex: MVVM (Model-View-ViewModel)

Advantages:
1. capability to create Single Page Application in a very clean and maintainable way.
2. It provides data binding capability to HTML.
3. AngularJS code is unit testable.
4. AngularJS provides reusable components .
5. write less and do more. ex:ng-repeat directive
6. AngularJS applications can run on all major browsers and smart phones, including Android and iOS based phones/tablets.

DisAdvantages:
1. If the user of your application disables JavaScript, then nothing would be visible, except the basic page.
2. JavaScript only framework, application written in AngularJS are not safe. Server side authentication and authorization is must to keep an application secure

Directives:
ng-app : This directive defines and links an AngularJS application to HTML.
ex: ng-app, ng-app = “appname”
ng-model : This directive binds the values of AngularJS application data to HTML input controls.
ex: <input type=”text” ng-model=”modelname” />
ng-bind : This directive binds the AngularJS application data to HTML tags.
ex1: <div data-ng-bind=”modelname”></div>
ex2: <div>{{modelname}}</div>

ng-init - This directive initializes application data.
ex:<div data-ng-init=”name=’bujji’”></div>
<div data-ng-bind=”name”></div>
o/p : bujji

MVC: Model View Controller or MVC as it is popularly called, is a software design pattern for developing web applications. A Model View Controller pattern is made up of the following three parts
Model - It is the lowest level of the pattern responsible for maintaining data.
View  - View - It is responsible for displaying all or a portion of the data to the user.
Controller : It is a software Code that controls the interactions between the Model and View.
Screen Shot 2015-03-03 at 7.22.10 pm.png

Angularjs Application Development Process:

1. Include the angularjs lib file(load the library).
2. Define Angularjs using data-ng-app
ex: <div data-ng-app=””></div>
3. Define modelname using data-ng-model
ex: Enter Name: <input type=”text” data-ng-model=”myname” />
4. Bind the model name using data-ng-bind
ex: <div data-ng-bind=”myname”></div>
(or)
     <div>{{myname}}</div>

First Example:
<!DOCTYPE html>
<html lang="en" data-ng-app="">
<head>
   <title>AngularJs Application</title>
</head>
<body>    
   <div>Enter Name: <input type="text" data-ng-model="myname"></div>
   <div>Hello <span data-ng-bind="myname"></span></div>
   <script src=”https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js”>     </script>    
</body>
</html>
Screen Shot 2015-03-03 at 7.16.40 pm.png


2. Develop Application using controller :
<!DOCTYPE html>
<html lang="en" data-ng-app="">
<head>
   <title>AngularJs Application</title>
</head>
<body data-ng-controller=”myCtrl”>
       <div><input type=”text” data-ng-model=”myname”/></div>
       <div><span data-ng-bind="myname"></span></div>
<button ng-click=”fnClick()”>click here</button>
<script>
function myCtrl($scope){
$scope.myname =’Welcome to Angularjs';
$scope.fnClick=function(){
console.log($scope.myname)
}
}
</script>    
</body>
</html>
o/p: Welcome to Angularjs

Note: here we are taking variable from controller and binding in view (html file)
above example we can observe controller to view and view to controller communication.

view      ---> controller
controoler ---> view


AngularJS Filters :
Filter: Selects a subset of items from array and returns it as a new array.
Filters can be added to expressions by using the pipe character | followed by a filter.
currency :(Formats a number as a currency)
Usage : {{ currency_expression | currency : symbol : fractionSize}}
Ex: <div ng-init="amount = 1234.56">
      <span>{{amount | currency}}</span>
 </div>
Result : $1,234.56
Ex: <span id="currency-no-fractions">{{amount | currency:"USD$":1}}</span>

Result : USD$1,234.6