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

Thursday, 25 December 2014

Important Html Tags

1. pre tag:
Text in a pre element is displayed in a fixed-width font, and it preserves both  spaces and line breaks.
<pre>
var persion = {
'fname':'bujji',
'lname':balaga',
'mobile':'9533068603'



};
</pre>

output :
var persion = {
'fname':'bujji',
'lname':balaga',
'mobile':'9533068603'



};

2. xmp tag:
  user want to display  html code in web page need to use xmp tag
ex:
<xmp>
<p>simple paragraph</p>
<div>simple div </div>
</xmp>

output:
<p>simple paragraph</p>
<div>simple div </div>

3.input tags :

<input type="text"/>
<input type="password"/>
<input type="email"/>
<input type="number"/>
<input type="date"/>
<input type="radio"/>
<input type="checkbox"/>
<input type="color"/>
<input type="month"/>
<input type="time"/>
<input type="datetime-local"/>
<input type="range"/>
<input type="tel"/>
<input type="search"/>
<input type="url"/>
<input type="week"/>
<input type="file"/>

4. auto complete

<datalist>
    <option value="attribute">
   <option value="bold">
  <option value="cource">
  <option value="data">
  <option value="element">
</datalist>


Open link in new window

Anchor :
we can open anchor tag in new window.
<a href="https://www.google.co.in/" onclick="window.open(this.href,'mywin','left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;">Share this</a>