Showing posts with label Javascript Interview Questions and Answers. Show all posts
Showing posts with label Javascript Interview Questions and Answers. Show all posts

Friday, 20 March 2015

What is the Correct content-type of JSON and JSONP?

What is the Correct content-type of JSON and JSONP?


Question: What is the Correct content-type of JSON?
  • application/json
  • application/javascript
  • application/x-javascript
  • text/javascript
  • text/x-javascript
  • text/x-json

Answer:
application/json

JSON is a domain-specific language (DSL) and a data format is independent of JavaScript it have its own MIME type i.e. application/json.

Example of JSON:
{ "Name": "Web Technology", "Website": "http://www.web-technology-experts-notes.in" }

Content-Type: application/json




Question: What is the Correct  content-type of JSONP?
  • application/json
  • application/x-javascript
  • application/javascript
  • text/javascript
  • text/x-javascript
  • text/x-json
Answer:
application/javascript

JSONP is JSON with padding. Response is JSON data but with a function call wrapped around it.

Example of JSONP:
functioncallExample({ "Name": "Web Technology", "Website": "http://www.web-technology-experts-notes.in" });

Content-Type: application/javascript



Tuesday, 10 February 2015

How to Call a javaScript function in PHP



You can't call a javascript function in PHP directly.

But You can Call a Javascript function from outputted HTML by PHP. It means you can call the javaScript function on conditional. See Example Below:
 
$count= empty($_GET['count'])?0:$_GET['count'];
if(empty($count)){
    echo '<script>callFunc1()</script>';
}elseif($count&lt;=10){
echo '<script>callFunc2()</script>';
}else{
echo '<script>callFunc3()</script>';
}

In this way, we call the JavasScript function in PHP.



Tuesday, 6 January 2015

Backbone Js interview questions and answers

Backbone Js interview questions and answers


Question: What is backbone Js?
It is JavaScript framework which helps to write the code in organize way and reduce the development time by providing lot of inbuilt functions. It also support MVC (Model, View, Controller). Its data binding framework.



Question: What is initial release date of backbone JS?
October 13, 2010



Question: What is current Stable Version and Release date?
1.3.2 / March 12, 2016



Question: In which language, backbone JS is writeen?
javaScript



Question: What is offical URL of Backbone JS?
http://backbonejs.org/



Question: What are main components of Backbone Js?
  • Model
  • View
  • controller
  • Router
  • Event class object


Question: What is Model in Backbone JS?
We use Model for retrieves the data from server.



Question: What is View in Backbone JS?
We use View for representation of HTML.



Question: What is controller in Backbone JS?
We use controller for writing application logic.


Question: What is Collection in Backbone JS?
Set of models are represented by collections.



Question: What is Router in Backbone JS?
application want to change their URL fragment.


Question: What is Model in Event class object JS?
events is a module that can be mixed in to any object.



Question: What are the three js files that you require to setup backbone Js?
  • jQuery
  • Backbone
  • Underscore


Question: What is the function of toJSON?
toJSON is used for persistence, serialization and for augmentation before being sent to the server.



Question: What are the configuration options available?
  • InitialCopyDirection
  • modelSetOptions
  • change Triggers
  • boundAttribute
  • suppressThrows
  • converter



Question: What are the keypoints of Backbone?
It has hard dependency with underscore.js to make it more functional and supporting.
With jQuery it has a soft dependency.
When the model changes it can update the HTML of your application automatically.
Significantly clean and elegant way for DOM manipulations and UI updates


Question: What is Backbone.sync?
When Backbone wants to save or read a model to the server it calls out a function called as Backbone.sync

Sunday, 4 January 2015

Front End Developer Interview Questions and Answers

Front End Developer Interview Questions and Answers

Question: What is the importance of the HTML DOCTYPE?
DOCTYPE is an instruction to the web browser about what version of the markup language the page is written. Its written before the HTML Tag. Doctype declaration refers to a Document Type Definition (DTD).


Question: Explain the difference between visibility:hidden; and display:none?
Visibility:Hidden; - It is not visible but takes up it's original space.
Display:None; - It is hidden and takes no space.


Question: How do you clear a floated element?
clear:both


Question: What is the difference between == and === ?
== is equal to
=== is exactly equal to (value and type)



Question: What is a java script object?
A collection of data containing both properties and methods. Each element in a document is an object. Using the DOM you can get at each of these elements/objects.



Question: Describe what "this" is in JavaScript?
this refers to the object which 'owns' the method.



Question: What is a closure?
Closures are expressions, usually functions, which can work with variables set within a certain context.


Question: How to use a function a Class?
function functionName(name) {  
    this.name = name;
}
// Creating an object
var functionName = new functionName("WTEN");  
console.log(functionName.name);  //WTEN



Question: What is Difference between null and undefined?
null is an object with no value. undefined is a type.
typeof null; // "object"  
typeof undefined; // "undefined"  



Question: What is the difference between HTML and XHTML?
HTML is HyperText Markup Language used to develop the website.
XHTML is modern version of HTML 4. XHTML is an HTML that follows the XML rules which should be well-formed.


Tuesday, 19 August 2014

Json Interview Questions And Answers For Freshers

Json Interview Questions And Answers For Freshers

Question: What is full Form JSON?
Answer: JavaScript Object Notation.


Question: What is JSON?
Answer: It is text-based standard design for interchange the information Between two or more different application. It is also very light as compare to XML and human readable.


Question: Who created the JSON?
Answer: Douglas Crockford


Question: Who is Father of JSON?
Answer: Douglas Crockford


Question: Why It is so popular?
Answer:
  1. It is light weight standard for exchange information
  2. It is independent of language
  3. It is independent of Hosting Server
  4. Human Readable
  5. Easy to Encode
  6. Easy to Decode
  7. Used in Mobile application



Question: Where JSON is used?
Answer: It is used to transfer the information between two application. Information can also be exchanged between two different application which is running on different OR same server. It is used in Web Application, Mobile Application (IOS, Android, Iphone, window Phone)


Question: What is file extension of JSON?
Answer: .json


Question: Why Use JSON over XML?
Answer: 

  1. It is light weight standard for exchange information.
  2. Human readable
  3. Easy to parse in PHP as well as in javaScript.
  4. Due to light weight It is fast.
  5. Question: Explain JSON Structures?
  6. Answer: It as an object, structure, or associative array where we stored data an ordered list.
  7. Each value have an key
  8. once key may have an further object
  9. Its lightweight that's why used in android application
  10. A JSON object begins with { and ends with } (braces)
  11. Each name is followed by : (colon) and the name/value pairs are separated by , (comma)


Question: Which Browser Support JSON?
Answer: JSON support is included in newer browsers and in the newest ECMAScript (JavaScript) standard.

  • Firefox (Mozilla) 3.5
  • Internet Explorer 8
  • Chrome
  • Opera 10
  • Safari 4



Question: What is JSON Parser?
Answer:JSON Parser is used to parse the JSON data into object to use its value. JSON can be parse by javaScript, jQuery and PHP.


Question: What is JSON-RPC?
Answer: Remote Procedure call protocol with use of JSON. It is similar to XML-RPC only difference, It use JSON instead of XML.

Question: What is JSON-RPC-Java?
Answer: JSON-RPC-Java is a Java implementation of the JSON-RPC protocol.


Question: How to create json from php array?
Answer:
$array = array('name'=>'PHP Tutorial','Description'=>'Web technology experts notes');
echo json_encode($array);


Question: How to get PHP array from json Object?
Answer:
$object='{"name":"PHP Tutorial","Description":"Expert in web technology"}';
$array = json_decode($object);


Question: How to parse JSON in JavaScript?
Answer:
var json = '{"name":"PHP Tutorial","Description":"Web technology experts notes"}'
    var obj = JSON.parse(json);
    //alert(obj.name);


Question: How to create JSON Object from JavaScript?
Answer:
var obj = {};
    obj['name']='php-tutorial-php.blogspot.in'; //string
    obj['age'] = 32;  // integer.
    obj['marks']= [80,70,60,50,60,80]; //array


Question: How to parse JSON in jQuery?
Answer:
var json = '{"name":"PHP Tutorial","Description":"Web technology experts notes"}'
    obj = $.parseJSON(json);
    //alert(obj.name);


Question: How to Validate json in php?
Answer:
$json = '{"name":"PHP Tutorial","Description":"Web technology experts notes"}';
$obj = json_decode($json);
if(is_null($obj)) {
 die('Invalid JSON');
}


Question: How to Validate json in javascript?
Answer:
function isValidJson(jsonData) {
    try {
        JSON.parse(jsonData);
        return true;
    } catch (e) {
        return false;
    }
}
var json = '{"name":"PHP Tutorial","Description":"Web technology experts notes"}'
isValidJson(json);


Question: How to Validate json in jQuery?
Answer:
 function isValidJson(jsonData) {
    try {
        $.parseJSON(jsonData);
        return true;
    } catch (e) {
        return false;
    }
}
var json = '{"name":"PHP Tutorial","Description":"Web technology experts notes"}'
isValidJson(json);


Question: How Convert json object to json string in jquery?
Answer:
var json = '{"name":"PHP Tutorial","Description":"Web technology experts notes"}'
JSON.stringify(json)


Question: How to convert json object to json string in javaScript?
Answer:
var json = '{"name":"PHP Tutorial","Description":"Web technology experts notes"}'
JSON.stringify(json)


Question: How to receive JSON Data at the Client Side?
Answer:
var json = '{"name":"PHP Tutorial","Description":"Web technology experts notes"}'
obj = $.parseJSON(json)


Question: How to get JSON response in Ajax?
Answer:
$.ajax({
  dataType: "json",
  url: '/ajax/url',
  data: 'name=php-tutorial-php',
  success: function(data){
  //data
  }
});


Question: What are online tool for Validate JSON data?
Answer:
http://jsonlint.com
http://www.freeformatter.com/json-validator.html


Question: What are JSON online tool for Formatter & Validator?
Answer: http://jsonlint.com/
http://www.freeformatter.com/json-validator.html
http://jsonviewer.stack.hu/
http://json.parser.online.fr/


Monday, 3 June 2013

Javascript Interview Questions and Answers


JavaScript is a general-purpose programming language designed to let programmers of all skill levels control the behavior of software objects. The language is used most widely today in Web browsers whose software objects tend to represent a variety of HTML elements in a document and the document itself. You can change the DOM element and call the Ajax. It is independent of operating and language.


Question: How many types of loop are there in javaScript?

Answer: JavaScript supports following different types of loops
for - loops through a block of code a number of times
for/in - loops through the properties of an object
while - loops through a block of code while a specified condition is true
do/while - also loops through a block of code while a specified condition is true
/** for loop example **/
cars=["BMW","Volvo","Merchi","Ford"];
var i=2,len=cars.length;
for (; i");
}
/** for loop example **/

/** For/In Loop **/
var person={fname:"John",lname:"Doe",age:25}; 

for (x in person)
  {
alert(person[x]);
  }
/** For/In Loop **/

/** while loop **/
while (i<5 data-blogger-escaped-br="" data-blogger-escaped-he="" data-blogger-escaped-i="" data-blogger-escaped-is="" data-blogger-escaped-number="" data-blogger-escaped-x="x">";
  i++;
  }
/** while loop **/ 


Question:What are global variables? How are they declared? How these are different from local variables?
Answer: Variable that are available throughout the page.
These are declared without use of var keyword.

Variable that are declared with use of keyword var are local variable and available within scope.
// Declare a local variable
var localVariable = "PHP Tutorial"
// Declare a global
globalVariable = "google"
 


Question:What is the difference between undefined and null?
Answer: The value of a variable with no value is undefined (i.e., it has not been initialized). Variables can be emptied by setting their value to null. You can use === operator to test this.


Question: What are the various datatypes in javascript?
Answer: Number - Store Number like 1,100, 33
String - Store string like "php","tutorial-" etc
Boolean - Store true OR false
Function - Store the function
Object - Store the object like person object
Null - Store the variable value null
Undefined - Not defined variable value are undefined.


Question: What is negative infinity?
Answer: It’s a number in JavaScript, derived by dividing negative number by zero. For example var a=-100/0;

Question: How to check the type of variable?
Answertypeof is used to check the variable type. For example alert(typeof abc);


Question: How do you convert numbers between different bases in JavaScript?
Answer: Use the parseInt() function.
alert( parseInt ("3F", 16));


Question: What is Javascript namespacing? How and where is it used?
Answer: Using global variables in Javascript is evil and a bad practice. That being said, namespacing is used to bundle up all your functionality using a unique name. In JavaScript, a namespace is really just an object that you’ve attached all further methods, properties and objects.


Question: How to load javascript files asynchronously?
Question: How to load javascript files fast?
 Answer: If you have latest browser which support HTML5 then you just need to add "async" tag with value true
If you have old browser, you need to create a js function that will add javascript async Following are the Javascript function example
function loadScriptAsync (scriptFilePath){
    var scriptHeadTag=document.getElementsByTagName('script')[0];
    var ss=document.createElement('script');
    ss.type='text/javascript';
    ss.async=true;
    ss.src= scriptFilePath
    scriptHeadTag.parentNode.insertBefore(ss,s);
}

loadScriptAsync('/js/jsfile.js'); 

Pass PHP Array into Ajax Call
//Setp 1: Include jQuery file in your page

$phpData = array('fname'=>'G', 'lname'=>'Geo','email'=>'g7789@gmaill.com'); //Setp 2: This is your PHP Array data

 [script]
/** Setp 3: This is Ajax Call will be called after page fully load **/
     function saveuserdetail(mydata) {                                    
                    $.ajax({
                        type: "POST",//Here you can use POST/GET Method
                        url: '/postpageurl/',
                        data: mydata,
                        success: function(msg){                            
                            console.log('Data'+msg);
                        },
                        dataType: 'json'
                    });                
            }
/** This is Ajax Call will be called after page fully load **/


/* Step 4: When Page Load, PHP Array will convert into javaScript Object */
/* Pass the javaScript Object into javaScript Function i.e saveuserdetail**/
$( document ).ready(function() {
    var data=new Object("echo json_encode($phpData) ")
    saveuserdetail(data);
});
[/script]

Question: Is JavaScript case sensitive?
Answer: Yes!
getElementById is different from getElementbyID.


Question: How will you get the Checkbox status whether it is checked or not?
Answer:
alert(document.getElementById('checkbox1').checked);


Question: How do you submit a form using JavaScript?
Answer:
document.forms[0].submit();


Question: What does isNaN function do?
Answer: isNaN : IsNotaNumber
returns true if the argument is not a number;

Question: What does "1"+9+4 evaluate to?
Answer: 194

How do you assign object properties?
obj["age"] = 22 or obj.age = 22.



What’s a way to append a value to an array?
arr[arr.length] = value;


How to read and write a file using javascript?
 I/O operations like reading or writing a file is not possible with client-side javascript.



How do you convert numbers between different bases in JavaScript?
Use the parseInt() function, that takes a string as the first parameter, and the base as a second parameter. So to convert hexadecimal FF to decimal, use parseInt ("FF", 16);



What is negative infinity? 
It’s a number in JavaScript, derived by dividing negative number by zero.



How to set a HTML document's background color?
 document.bgcolor property can be set to any appropriate color.



What boolean operators does JavaScript support?
&&, and !



How to get the contents of an input box using Javascript?
 Use the "value" property.var myValue = window.document.getElementById("textboxID").value;



How to determine the state of a checkbox using Javascript? 
var checkedP = window.document.getElementById("CheckBoxID").checked;



How to set the focus in an element using Javascript? 
<script> function setFocus() { if(focusElement != null) { document.forms[0].elements["myelementname"].focus(); } } </script>



How to access an external javascript file that is stored externally and not embedded? 
This can be achieved by using the following tag between head tags or between body tags.<script src="raj.js"></script>How to access an external javascript file that is stored externally and not embedded? where abc.js is the external javscript file to be accessed.



What is the difference between an alert box and a confirmation box? 
An alert box displays only one button which is the OK button whereas the Confirm box displays two buttons namely OK and cancel.



What is a prompt box? 
A prompt box allows the user to enter input by providing a text box.



Can javascript code be broken in different lines?
Breaking is possible within a string statement by using a backslash \ at the end but not within any other javascript statement.that is ,document.write("Hello \ world");is possible but not document.write \("hello world");



What looping structures are there in JavaScript?
for, while, do-while loops, but no foreach.



How do you create a new object in JavaScript?
var obj = new Object(); or var obj = {};



What is this keyword?
It refers to the current object.


What is the difference between SessionState and ViewState? 
ViewState is specific to a page in a session. Session state refers to user specific data that can be accessed across all pages in the web application.

What looping structures are there in JavaScript? 
for, while, do-while loops, but no foreach.



To put a "close window" link on a page ? 
<a href='javascript:window.close()'> Close </a>



How to comment javascript code? 
Use // for line comments and/**/ for block comments



Name the numeric constants representing max,min values 
Number.MAX_VALUENumber.MIN_VALUE



What does javascript null mean? The null value is a unique value representing no value or no object.It implies no object,or null string,no valid boolean value,no number and no array object.



How do you create a new object in JavaScript? 
var obj = new Object(); or var obj = {};



How do you assign object properties? 
obj["age"] = 23 or obj.age = 23.



What’s a way to append a value to an array? 
arr[arr.length] = value;


What does undefined value mean in javascript? 
Undefined value means the variable used in the code doesn't exist or is not assigned any value or the property doesn't exist.



What is the difference between undefined value and null value? 
(i)Undefined value cannot be explicitly stated that is there is no keyword called undefined whereas null value has keyword called null(ii)typeof undefined variable or property returns undefined whereas typeof null value returns object



What is variable typing in javascript? It is perfectly legal to assign a number to a variable and then assign a string to the same variable as followsexamplei = 10;i = "string";This is called variable typing



Does javascript have the concept level scope? No. JavaScript does not have block level scope, all the variables declared inside a function possess the same level of scope unlike c,c++,java.

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

How to disable an HTML object ?
document.getElementById("myObject").disabled = true;



How to create a popup warning box?
alert('Warning: Please enter an integer between 0 and 1000.');



How to create a confirmation box? 
confirm("Do you really want to launch the missile?");



How to create an input box? 
prompt("What is your temperature?");


What's Math Constants and Functions using JavaScript? 
The Math object contains useful constants such as Math.PI, Math.EMath.abs(value); //absolute valueMath.max(value1, value2); //find the largestMath.random() //generate a decimal number between 0 and 1Math.floor(Math.random()*101) //generate a decimal number between 0 and 100



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



How to get value from a textbox?
alert(document.getElementById('txtbox1').value);



How to get value from dropdown (select) control?alert(document.getElementById('dropdown1').value);


What is console.log?
It is feature of Firebug used for debug the javascript OR jQuery code. It can print the string, number, array OR object. It is same as print_r() in php.

Example of console.log
console.log (22 );
console.log ('web technology experts notes' );
console.log (arrayVal);
console.log (objectVal);



Question: How to check checkbox is checked or not in jquery?
$('.checkBoxClass').is(':checked');


Question: How to check the checkbox as checked?
$(".checkBoxClass").attr('checked', true); // Deprecated
$(".checkBoxClass").prop('checked', true);


Best Related Posts are Following:
1. jQuery Mobile interview questions and answers
2. Ajax Interview questions and answers for experienced
3. Advanced MySQL Interview Questions and Answers for Experienced
4. SAML Interview Questions and Answers
5. HTML5 interview Questions and Answers for Fresher and Experienced
6. Backbone Js interview questions and answers
7. Bootstrap Interview Questions and Answers for Experienced
8. HTML interview questions and Answers
9. SEO Interview Questions and Answers
10. AngularJS Interview Questions and Answers for Experienced
11. Difference Between Hadoop and Big-Data
12. Memcached interview questions and answers
13. General Interview Questions and Answers
14. UNIX Commands Interview Questions and Answers
15. Apache Interview Questions and Answers
16. PHP Technical Interview Questions and Answers
17. Zend Framework Interview Questions and Answers for Experienced - Page 2
18. CSS Interview Questions and Answers
19. Mysql Interview Questions And Answers - Atomicity, Dedlock, Client Program, Mysql Mode, Mysql Sensitivity Of Identifiers And Mysql Errors
20. Zend Framework Interview Questions and Answers for Experienced
21. XML Interview Questions And Answers