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/