Posts

Express and Node JS Interview Questions

What is Node JS?

Node Js is one of the most popular and powerful server technologies today. It allows you to built the entire website only in one programming Language i.e Javascript. Node js is free and open-source server technology that uses Javascript to create complete web software. It runs on various platforms like Windows, Linux, Unix, Mac OS X, etc.

Quick Questions About Node JS
Node Js is written InC, C++, JavaScript Programming Language
Node Js is aOpen Source server Technology for creating mobile APIs and web apps.
Node Js is developed ByRyan Dahl
Node Js SupportsLinux, macOS, Microsoft Windows, SmartOS, FreeBSD, OpenBSD, IBM AIX Operating Systems
Node Js DependenciesV8, libuv, http-parser, c-ares, OpenSSL, zlib, Tools, npm, gyp, gtest
Node Js LicenceMIT License
Node Js Current Stable release10.16.0

Below are the list of Best Node JS Interview Questions with Express and Answers

Question 1. What is Node js ?

Node Js is one of the most popular and powerful server technologies today.
It allows you built the entire website only in one programming Language i.e Javascript. Node js is free and open source server technology that uses Javascript to create complete web software.It runs on various platforms like Windows, Linux, Unix, Mac OS X, etc.

Question 2. Explain CLI in Node.js?

CLI stands for Command Line Interface. It is a utility or program on your computer where users type commands to perform some action or run some script rather than clicking on the screen.
There are different types of command line interfaces depending on which operating system you are using. We have listed some of them below.

  • Bash on Linux.
  • Terminal of Mac.
  • Command Prompt or Powershell on Windows
  • Shell/ Command line/terminal on Unix and Ubuntu

Question 3. In which Language Node Js is written ?

Node js is written in C, C++,JavaScript.It uses Google’s open source V8 Javascript Engine to convert Javascript code to C++.

Question 4. Who is the author of Node Js ?

Node Js is written by Ryan Dahl.

Question 5. Explain What is a Javascript Engine ?

A Javascript Engine is a program that converts code written in Javascript to something that computer processor understands.

Question 6. Explain V8 Engine ?

V8 is Google’s open source high-performance JavaScript engine, written in C++ and used in Google Chrome, the open source browser from Google, and in Node.js, among others. It implements ECMAScript as specified in ECMA-262, and runs on Windows 7 or later, macOS 10.5+, and Linux systems that use IA-32, ARM, or MIPS processors. V8 can run standalone or can be embedded into any C++ application.
Source: https://developers.google.com/v8/

Question 7. Explain ECMAScript ?

ECMAScript is the standard on which Javascript is based on. It was created to standardize Javascript. It is commonly used for client-side scripting on the World Wide Web and used by Node Js for writing server applications and services.

Question 8. How can you check the installed version of Node Js ?

Use node -v command to check the installed version of Node Js.

Question 9. Explain What is NPM ?

NPM stands for node package manager. It is default Package Manager for JavaScript programming language. NPM is used for installing/updating packages and modules of Javascript.

Question 10. Explain Modules in Node Js ?

Modules are reusable block of code whose existence does not impact other code in any way. It is not supported by Javascript. Modules are introduced in ES6. Modules are important for Maintainability, Reusability, and Namespacing of Code.

Question 11. What are CommonJs Modules ?

CommonJS Modules is the Standard how to code modules are structured. It specifies an ecosystem for JavaScript outside on the server or for native desktop applications.

Question 12. For what require() is used in Node Js ?

require() is used to include modules from external files in Node Js. It is the easiest way to include a module in Node. Basically require is a function that takes a string parameter which contains the location of the file that you want to include. It reads the entire javascript file, executes the file, and then proceeds to return the exports object.
Syntax:

require('path');

Question 13. Explain module.exports in Node Js ?

The method or variable defined in modules cannot be directly accessible by the outer world, that means you cannot call a module member from the external file. In order to access module member, we need to export the functions or variables of modules using module.exports method.

Syntax and usage:

// greet.js
var greet=function(){
console.log("hello World");
}
module.exports=greet;

//In app.js

var greet=require('./greet.js');

greet();

Question 14. Is Node Js Single-threaded ?

Yes, Node Js is single threaded to perform asynchronous processing. Doing async processing on a single thread could provide more performance and scalability under typical web loads than the typical thread-based implementation.

Question 15. What are events ?

An event is an action or occurrence recognized by software/app that is handled by event handler by writing a code that will be executed when the event fired.
Mouse move, Click, file copied or deleted are some examples of events.
In Node Js there are two types of events.
1)System Events: The event that comes from the C++ side.
2)Custom Events: Custom events are user-defined events.

Question 16. Explain event loop in Node Js ?

In Node Js processes are single threaded, to supports concurrency it uses events and callbacks. An event loop is a mechanism that allows Node.js to perform non-blocking I/O operations.

Question 17. How to create a simple server in Node js that returns Hello World ?

By writing following line of code, you can create a server in Node Js.

var http =require('http');
http.createServer(function(req,res){

res.writeHead(200,{'Content-Type':'text/plain'});
res.end('Hello World\n');

}).listen(1320,'127.0.0.3');

Question 18. Difference between cluster and child_process modules?

Question 19. How to stop master process without suspending all of its child processes?

Question 20. What does emitter do and what is dispatcher?

Question 21. Since node is a single threaded process, how to make use of all CPUs?

Question 22. List some features of Express JS.

Some of the main features of Express JS are listed below: –

  • It is used for setting up middlewares so as to provide a response to the HTTP or RESTful requests.
  • With the help of express JS, the routing table can be defined for performing various HTTP operations.
  • It is also used for dynamically rendering HTML pages which are based on passing arguments to the templates.
  • It provides each and every feature which is provided by core Node JS.
  • The performance of Express JS is adequate due to the presence of a thin layer prepared by the Express JS.
  • It is used for organizing the web applications into the MVC architecture.
  • Everything from routes to rendering view and performing HTTP requests can be managed by Express JS.

Question 23. Write the steps for setting up an Express JS application.

Following are the steps used to set up an express JS application: –

  1. A folder with the same name as the project name is created.
  2. A file named package.json is created inside the folder created.
  3. “npm install” command is run on the command prompt. It installs all the libraries present in package.json.
  4. A file named server.js is created.
  5. “Router” file is created inside the package which consists of a folder named index.js.
  6. “App” is created inside the package which has the index.html file.

This way, an express JS application is set up.

Question 24. What do you mean by Express JS?

Express JS is an application framework which is light-weighted node JS. A number of flexible, useful and important features are provided by this JavaScript framework for the development of mobile as well as web applications with the help of node JS.

Question 25. Name the type of web applications which can be built using Express JS.

Single-page, multi-page, and hybrid web applications can be built using Express JS.

Question 26. What is the use of Express JS?

Express.js is a lightweight web application which helps in organizing the web application into MVC architecture on the server side.

Question 27. What function are arguments available to Express JS route handlers?

The arguments which are available to an Express JS route handler-function are-

  • Req – the request object
  • Res – the response object
  • Next (optional) – a function which is used to pass control to one of the subsequent route handlers.

The third argument is optional and may be omitted, but in some cases, it is useful where there is a chain of handlers and control can be passed to one of the subsequent route handlers skipping the current one.

Question 28. How to config properties in Express JS?

In Express JS, there are two ways for configuring the properties:

  • With process.ENV:
  • A file with the name “.env” is to be created inside the project folder.
  • All the properties are to be added in the “.env” file.
  • Any of the properties can be used in server.js.
  • With require JS:
  • A file with the name “config.json” is to be created in the config folder inside the project folder.
  • The config properties are to be added in the config.json file.
  • Now, require should be used to access the config.json file.

Question 29. How can models be defined in Express JS?

There is no notion of any database in Express JS. So, the concept of models is left up to third-party node modules, allowing the users to interface with nearly any type of database.

Question 30. How to authenticate users in express JS?

Since authentication is an opinionated area which is not ventured by express JS, therefore any authentication scheme can be used in express JS for the authentication of users.

Question 31. Which template engine is supported by express JS?

Express JS supports any template engine that conforms to the (path, locals, callback) signature.

Question 32. How can plain HTML be rendered in express JS?

There’s no need to render HTML with the res.render () function. If there’s a specific file, then you should use the res.sendFile () function. If any assets are being served from a dictionary, then express.static () middleware function needs to be used.

Question 33. Why to use Express.js?

Below are the few reasons why to use Express with Node.js

  • Express js is built on top of Node.js. It is the perfect framework for ultra-fast Input / Output.
  • Cross Platform
  • Support MVC Design pattern
  • Support of NoSQL databases out of the box.
  • Multiple templating engine support i.e. Jade or EJS which reduces the amount of HTML code you have to write for a page.
  • Support Middleware, basic web-server creation, and easy routing tools.

Question 34. Explain the difference between readFile and createReadStream in Node js ?

  • readFile load the whole file which you had marked to read whereas createReadStream reads the complete file in the parts of the size you have declared.
  • The client will receive the data faster in the case of createReadStream in contrast with readFile.
  • In readFile, a file will first completely read by memory and then transfers to a client but in later option, a file will be read by memory in a part which is sent to clients and the process continue until all the parts finish.

Question 35. List types of Http requests?

Http defines a set of request methods to perform the desired actions. These request methods are:

  1. GET: The GET method asked for the representation of the specifies resource. This request used to retrieve the data.
  2. POST: The POST technique is utilized to present an element to the predetermined resource, generally causing a change in state or reactions on the server.
  3. HEAD: The HEAD method is similar to the GET method but asks for the response without the response body.
  4. PUT: This method is used to substitute all current representations with the payload.
  5. DELETE: It is used to delete the predetermined resource.
  6. CONNECT: This request is used to settle the TCP/IP tunnel to the server by the target resource
  7. OPTION: This method is used to give back the HTTP strategies to communicate with the target resource.
  8. TRACE: This method echoes the message which tells the customer how much progressions have been made by an intermediate server.
  9. PATCH: The PATCH method gives partial modifications to a resource.

Question 36. What is difference between put and patch?

The main difference between the put and the patch is

PutPatch
The embedded entity is believed to the modified version of the resources that are deposited on the original server. It is requested to the client to replace the stored is substituted.In this, the information regarding the way of modifying the original server which has the resources to produce a new version is found.
At the time of updating the resource, you need to forward full payload as the request.At the time of updating the resource, you only need to send the parameter of the resource which you want to update.

Question 37. How can you set default node version using nvm?

Run below command on the terminal to set default node version along multiple installed versions of node. You can list all install versions of the node by running nvm ls

nvm alias default v7.3.0

Question 38. How to generate unique UUIDs/ guid in Node Js

Use node-uuid package to generate unique UUIDs/ guid in Node Js. Below code demonstrates how to generate it.

var uuid = require('node-uuid');

// Generate a v1 (time-based) id 
uuid.v1(); 

// Generate a v4 (random) id 
uuid.v4(); 

Question 39. Write a simple code to enable CORS in Node js?

CORS stands for Cross-Origin Resource Sharing. It a is a mechanism that uses additional HTTP headers to tell a browser to let a web application running at one origin (domain) have permission to access selected resources from a server at a different origin.

Use below code to enable CORS on NodeJS

app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  next();
});

Question 40. List the types of application you can build using Node Js ?

Using Node Js you can build applications like:

  • Internet of Things
  • Real-Time Chats Applications
  • Complex Single-Page Applications
  • Real-Time Collaboration Tools
  • Streaming apps
  • Microservices / API’s

Question 41. Explain what is libuv in Node Js ?

libuv is Cross-platform I/O abstraction library that supports asynchronous I/O based on event loops.It is written in C and released under MIT Licence.

libuv support Windows IOCP, epoll(4), kqueue(2), and Solaris event ports. Initially, it was designed for Node.js but later it is also used by other software projects.

Reference : https://en.wikipedia.org/wiki/Libuv

Question 42. Why Zlib is used in Node js ?

Zlib is Cross-platform data compression library. It was written by Jean-loup Gailly and Mark Adler. In Node js, you can Zlib for Threadpool, HTTP requests, and responses compression and Memory Usage Tuning. In order to use zlib in node js, you need to install node-zlib package. After installation below is sample code to use Zlib.

var Buffer = require('buffer').Buffer;
var zlib = require('zlib');

var input = new Buffer('lorem ipsum dolor sit amet');
var compressed = zlib.deflate(input);
var output = zlib.inflate(compressed);

Further Reading https://nodejs.org/api/zlib.html

https://en.wikipedia.org/wiki/Zlib

Question 43. Write a program to Print 0 to N element in pyramid shape?

Question 44. List out some new features introduced in ES6?

Following are the list of few new Features introduced in ES6

  • const and let keywords
  • Array helper functions like map, forEach, filter, find, every, some, reduce
  • Arrow functions
  • Classes and enhanced object literals
  • Template strings
  • Default function arguments
  • Rest and spread operators
  • Promises
  • Modules
  • Multi-line Strings
  • Destructuring Assignment

Question 45. What is JIT and how is it related to Node JS ?

JIT stands for Just-in-time. A JIT compiler is a program which is used to send bytecode (it consists of instruction that can be interpreted) to the processor by converting it into instruction. After you have done with writing a program, the compiler compiles the source language statements into bytecode instead of compiling it into the code that carries the information which is similar to the specific hardware platform’s processor.

Relation of JIT with Node: Virtual machine of Nodejs has JIT compilation which improves the execution speed of the code. The virtual machine takes the source code and converts to machine code in runtime. By this, the hot functions which are called very often are compiled to machine code and, hence increasing speed.

Question 46. How to use aggregation in Mongoose?

Aggregations are a set of functions that are used to manipulate the data that has been returned from a MongoDB query. In Mongoose, aggregations work as a pipeline. The aggregate function accepts the array of data transformations which are applied by data using different methods in terms of arguments.

Syntax: db.customers.aggregate([ … aggregation steps go here …]);

In above, aggregation is applied to data of customers.

Question 47. How Node js read the content of a file?

Normally NodeJs reads the content of a file in non-blocking, asynchronous way. Node Js uses its fs core API to deal with files. The easiest way to read the entire content of a file in nodeJs is with fs.readFile method. Below is sample code to read a file in NodeJs asynchronously and synchronously.

Reading a file in node asynchronously/ non-blocking

var fs = require('fs'); 
fs.readFile('DATA', 'utf8', function(err, contents) {
    console.log(contents);
});
console.log('after calling readFile');

Reading a file in node asynchronously/blocking

var fs = require('fs'); 
var contents = fs.readFileSync('DATA', 'utf8');
console.log(contents);

Question 48. How Promises are better than callbacks?

Question 49. Describe Node.js event loop and event driver architecture?

Question 50. What are Streams? List types of streams available in Node Js ?

Streams are special types of objects in Node that allow us to read data from a source or write data to a destination continuously. There are 4 types of streams available in Node Js, they are

  • Readable − For reading operation.
  • Writable − For writing operation.
  • Duplex − Used for both read and write operation.
  • Transform − A type of duplex stream where the output is computed based on the input.

Further reading: https://www.tutorialspoint.com/nodejs/nodejs_streams.htm

Question 51. What is difference between return and callback in JavaScript functions?

Question 52. How does Promise and Queue work?

Question 53. What’s the first argument passed to a Node Js callback handler?

In Node Js all core modules, as well as most of the community-published modules, follows a pattern where the first argument to any callback handler is an error object. this object is optional, if there is no error then in that case null or undefined is passed to the callback.

Example of the callback function

function callback(err, results) {
	// usually we'll check for the error before handling results
	if(err) {
		// handle error somehow and return
	}
		// no error, perform standard callback handling
}

Question 54. What do you understand by middleware? How can you use middleware in Node Js?

Question 55. Explain the difference between process.tick() and setImmediate() ?

Question 56. What is the revealing module pattern?

Revealing module pattern is similar to Module Pattern.IT ExposES only the properties and methods you want via an returned Object.

var greeting = 'Hello world'
function greet() {
 console.log(greeting)
}
module.exports = {
  greet: greet
}

Question 57. what is Closures?

A Closure is a function defined within another scope that has access to all the variables within the outer scope.

Global variables can be made local (private) with closures.

Got a Questions? Share with us

Ajax Interview Questions

Question 1) Brief about Ajax.
Question 2) Differentiate between Synchronous and Asynchronous Ajax requests.
Question 3) List some advantages and disadvantages of using Ajax.
Question 4) What are different readyState in Ajax.
Question 5) What is XMLHttpRequest object in Ajax? How can you XMLHttpRequest Object?
Question 6) How to cancel the current request in Ajax?
Question 7) How to send an Ajax request in JavaScript?
Question 8) Explain Fetch API in JavaScript.
Question 9) Explain limitations of Ajax.
Question 10) Explain what is polling in AJAX.

What is AJAX

AJAX or Asynchronous Javascript and XML is one of the most preferred platforms used by developers. We also find its application in several industries and verticals as it offers unique features. A lot of brands hire developers who can work on this platform so that they can get their websites designed on it. The platform seems promising as it can build interactive web applications, which are required for retaining the visiting customer and engaging them for a longer duration. This is one of the factors that increases the page ranking on SERP. Today the demand for the AJAX developers has increased and corporate houses and business owners are looking forward to hiring them. Almost every organization is trying to hold up a strong social presence and therefore developers are hired to make the presence even stronger among the potential customers. The interview for the developers can be tough as the competition is really high and the market is full of talent. While some prefer general knowledge of programming other interviewers can ask technical questions. Thus, here is a list of compiled possibly Ajax interview questions that can be asked by an interviewer:

Below are the list of Best Ajax Interview Questions and Answers

Question 1) Brief about Ajax.

Ajax is considered to be a developer’s best friend because it offers several benefits to him such as updating the web page without reloading the entire page, requesting data from the server and also sending data to the server. AJAX is the acronym for Asynchronous JavaScript and XML. It is a new technique to communicate to and from a server/ database without completely refreshing the page. It creates faster, interactive, better web applications with help of CSS, XML, HTML, and JavaScript.

Question 2) Differentiate between Synchronous and Asynchronous Ajax requests.

Synchronous Ajax requests: In this, the script stops and waits for the server to reply before continuing. In the web application world, one has to happen after the other, i.e. the interaction between the customer and the server is synchronous. Synchronous is not recommended as it blocks/hangs the page until the response is received from the server.

Asynchronous Ajax requests handle the reply as and when it comes and allows the page to continue to be processed. Under Asynchronous, if there is any problem in the request it can be modified and recovered. The request doesn’t block the client as the browser is responsive. The user can perform other operations as well.

Question 3) List some advantages and disadvantages of using Ajax.

Ajax is a very easy concept if one has a sound knowledge of JavaScript. It uses JavaScript functions to call methods from a web service. It has certain advantages-

  • Speed– Ajax reduces the server traffic and also the time consumption on the server and client side.
  • Ajax is very responsive and fast, data can be transferred at a time.
  • XMLHttpRequest plays a significant role in Ajax. It is a special JavaScript object that calls asynchronous HTTP request to the server for transferring data.
  • One of the biggest advantages of using Ajax as forms are common elements in the web page. Ajax gives options for validation and much more.
  • One doesn’t have to completely reload the page.

There are some disadvantages attached to Ajax. They are-

  • Search engines would not be able to index Ajax applications so Ajax maybe a mistake.
  • Anyone can have access to the code of Ajax and can view source it.
  • ActiveX requests are enabled only in internet explorer and other new browsers.

Question 4) What are different readyState in Ajax.

There are total 5 ready state in Ajax:

ValueStateDescription
0UNSETClient has been created. Open() not yet called.
1OPENEDOpen() called.
2HEADRERS_RECIEVEDSend() called and headers are available.
3LOADINGDownloading: responseText holds partial data.
4DONEThe operation is complete.

Question 5) What is XMLHttpRequest object in Ajax? How can you XMLHttpRequest Object?

The XMLHttpRequest objects are used to exchange data with a server. It is an API whose methods transfer between a web browser and a web server. In XHR, it’s not necessary that data have to be in form of XML. It can be JSON or HTML. XHR can be used with protocols other than HTTP.

XMLHttpRequest is any developers kit because it has the option to update the page without reloading the entire page. You can request data from the server and also send data to the server in the background.

Question 6) How to cancel the current request in Ajax?

Current request in AJAX is cancelled when the user performs an action which sets of an Ajax request. This can be depicted with the help of auto-complete functionality for a search box where users can be helped with related search terms based on their current input, by making an AJAX request each time they pass a key in search field. The user types faster than the Ajax request and you would want to abort any non-finished requests, before starting the next one.

Question 7) How to send an Ajax request in JavaScript?

HTTP Requests are created with the help of XMLHttpRequest objects. It facilitates the transfer of data between client and server which happens via request and response. In XMLHttpRequest, you can perform the same function plus you can grab data from URL without having to refresh the page. AJAX lets you perform actions without reloading the entire page. The following steps tell how to call AJAX-

  • Create an XMLHttpRequest object.
  • Open the request with open method.
  • Now, send the request with the send method.

var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
     document.getElementById("demo").innerHTML = this.responseText;
    }
  };
  xhttp.open("GET", "get_results.php", true);
  xhttp.send();

Question 8) Explain Fetch API in JavaScript.

Fetch API uses to request and response objects that can be used in future whenever needed. It provides an interface for fetching resources. Fetch API uses promises that enable cleaner API. Cache API or other similar things handles the request and responses that might require you to generate your own responses programmatically.

Thus, you can now crack your interview and work as a developer in one of your dream companies by preparing from these set of question and answers to be technically sound.

Question 9) Explain limitations of Ajax.

1) Browser Integration

The dynamically created page does not register itself with the browser history engine, so triggering the “Back” function of the users’ browser might not bring the desired result.

2) Response-time Concerns

Network latency – or the interval between the user request and server response – need to be considered carefully during Ajax development.

3) Search Engine Optimization (SEO)

Websites that use Ajax to load data which should be indexed by search engines must be careful to provide equivalent Sitemaps data at a public, linked URL that the search engine can read, as search engines do not generally execute the JavaScript code required for Ajax functionality.

4) Reliance on JavaScript

Ajax relies on JavaScript, which is often implemented differently by different browsers or versions of a particular browser. Because of this, sites that use JavaScript may need to be tested in multiple browsers to check for compatibility issues.

Question 10) Explain what is polling in AJAX.

The Process of retrieving data from a server to obtain near-live data regularly is called AJAX polling.

Got a Questions? Share with us

Aurelia Interview Questions

Question 1) Explain Aurelia ?

Aurelia is a JavaScript-based client framework for the web, mobile, and desktop that leverages simple conventions to empower your creativity.

Find Top Aurelia interview questions and answers from below

Below are the list of Best Aurelia Interview Questions and Answers

Question 1) Explain Aurelia ?

Aurelia is a JavaScript based client framework for web, mobile and desktop that leverages simple conventions to empower your creativity.

Got a Questions? Share with us

Backbone js Interview Questions

Question 1) Explain what is Backbonejs?
Question 2) List Dependencies of using BackboneJs?
Question 3) What is the use of BackboneJS route?
Question 4) What is a collection in Backbone.js?
Question 5) What are the main BackboneJs native components?
Question 6) Explain Events in BackboneJs?
Question 7) What is the difference between the properties “id” and “cid” on a model object in Backbone Js?
Question 8) List out configuration options available in Backbone Js?
Question 9) What is Modelbinder in Backbone Js ?
Question 10) What is a converter in Backbone Js ?
Question 11) Explain Architecture of Backbone?
Question 12) What is Backbone.sync is used for?
Question 13) Explain what is ModelBinder in Backbone.js?
Question 14) How to access a models data from a view in Backbone.js?
Question 15) How are models attributes stored in Backbone.js?
Question 16) What is Router in Backbone? How do you create a Router with Backbone?
Question 17) What is Collection in Backbone?
Question 18) How to Create a Model In Backbone js?

Top Backbone js interview questions and Answers for freshers and experienced.

Below are the list of top 18 Backbone js interview questions. Here You can read interview questions on Backbone js.

Below are the list of Best Backbone js Interview Questions and Answers

Question 1) Explain what is Backbonejs?

Backbone.js is a client-side (Model, View, Controller) MVC-based JavaScript framework. It purely is written in Javascript.

Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.

Question 2) List Dependencies of using BackboneJs?

Backbone’s Js only hard dependency is Underscore.js ( >= 1.8.3). For RESTful persistence and DOM manipulation with Backbone. View, include jQuery ( >= 1.11.0), and json2.js for older Internet Explorer support. (Mimics of the Underscore and jQuery APIs, such as Lodash and Zepto, will also tend to work, with varying degrees of compatibility.)

Question 3) What is the use of BackboneJS route?

The Backbone.js router is used to change the URL fragment or hashes of an application to create bookmarkable and shareable URLs.

Question 4) What is a collection in Backbone.js?

In Backbone.js, the collection is used to represent ordered set of models. Any event in model triggers an event in collection directly. For example, you can bind “change” event to be notified in a case when any model in the collection has been modified.

Question 5) What are the main BackboneJs native components?

The main native components of BackboneJs are:-

  • Model
  • View
  • Collection
  • Router
  • Event class object

Question 6) Explain Events in BackboneJs?

Backbone events is a module that can be mixed into any object, giving the object the ability to bind and trigger custom named events. Events are not declared before they are bound to any object. Events reflect the state of the model.

Question 7) What is the difference between the properties “id” and “cid” on a model object in Backbone Js?

The “id” property on a model is automatically assigned based on the “id” set in the model’s attributes hash.

Ideally, this is the ID that you receive from the rest API for the resource that you are querying. On the other hand, “cid” is an ID temporarily assigned to each model and is useful until an actual ID is determined for the object. For example, a model pushed to a collection that has not yet been persisted can be addressed using “cid”, until it is saved in the database and an actual ID is generated for it.

Question 8) List out configuration options available in Backbone Js?

  • InitialCopyDirection
  • modelSetOptions
  • change Triggers
  • boundAttribute
  • suppressThrows
  • converter

Question 9) What is Modelbinder in Backbone Js ?

ModelBinder class is used to make synchronization process of views and models together.

Question 10) What is a converter in Backbone Js ?

When a model’s attribute is copied to an HTML element or when an HTML element’s value is copied into a model’s attribute, a function is called, this function is known as a converter in Backbone Js.

Question 11) Explain Architecture of Backbone?

Question 12) What is Backbone.sync is used for?

Backbone.sync is a function that is Backbone js call every time it attempts to read or save a model to the server.By default, it uses jQuery.ajax to make a RESTful JSON request and returns a jqXHR

Example Code

Backbone.sync = function(method, model) {
  alert(method + ": " + JSON.stringify(model));
  model.set('id', 1);
};

var author= new Backbone.Model({
  author: "Sharad",
  website: "https://www.onlineinterviewquestions.com"
});

author.save();

author.save({author: "Teddy"});

Question 13) Explain what is ModelBinder in Backbone.js?

ModelBinder is a class in Backbone.js to bind backbone model attributes to:

  • Read-only html elements such as <span>, <div> etc.
  • Html element attributes such as enabled, displayed, style etc.
  • Editable form elements such as <input>, <textarea> etc. This type of binding is bidirectional between the HTML elements and the Model’s attributes.

Question 14) How to access a models data from a view in Backbone.js?

In order to access a models data from a view in backbone.js you have to initialize your Model :

var author= Backbone.Model.extend({
      initialize: function(){
        console.log('intailized');
      },
      defaults:{
          names:['Bob','Sim','Dart']
      }
    })
var person_view = Backbone.View.extend({
    initialize: function() {
        this.model = new author();
    },
    output: function(){
        console.log(this.model.get('names'))
    }
});

Question 15) How are models attributes stored in Backbone.js?

In Backbone.js models attributes stored in a hash.

Question 16) What is Router in Backbone? How do you create a Router with Backbone?

Backbone Router is used for routing client-side applications and connects them to actions and events using URLs. Backbone.Router is used to create a Router with Backbone.

Question 17) What is Collection in Backbone?

A collection is a set of models which binds events when the model has been modified in the collection. The collection contains a list of models that can be processed in the loop and supports sorting and filtering. When creating a collection, we can define what type of model that collection is going to have along with the instance of properties. Any event triggered on a model, which will also trigger on the collection in the model.

Question 18) How to Create a Model In Backbone js?

Creating a Model in Backbone Js

Person = Backbone.Model.extend({
initialize: function(){
alert("Welcome to Backbone Js");
}
});

var person = new Person;
Got a Questions? Share with us

D3.js interview questions

Question 1) Define D3.js?
Question 2) What does D3 stand for?
Question 3) Who developed D3.js?
Question 4) Why use to D3.js?
Question 5) How D3.js identify on which elements to operate?
Question 6) Explain selections in D3.js ?
Question 7) Explain, what is the use of “Enter” and “Exit” selection in D3.js ?
Question 8) List Type of sliders are available in D3.js?
Question 9) Explain transition in D3.js?
Question 10) List the command to interpolate two objects in D3.js?
Question 11) which is the correct way to use XML file for d3?
Question 12) What is the best way to create the stacked chart in d3 js?
Question 13) How to import XML data using d3.js?
Question 14) Which is not a valid scale in d3 js?
Question 15) What is different between d3.scale.linear() and d3.scaleLinear().
Question 16) How to alter zoom modes in d3 js?
Question 17) How to set initial zoom level in D3.js?
Question 18) How to resize an SVG when the window is resized in d3.js?
Question 19) How to get Mouse position in D3.js?
Question 20) What is the difference between canvas and SVG in d3.js?
Question 21) How to format the date in d3.js?
Question 22) List types of loops available in D3.js with syntax?
Question 23) Explain axes in D3.js?How to create d3.js axes without numbering?
Question 24) Explain Transition is D3.js?
Question 25) How to calculate the area of the polygon in d3.js?

D3.js is defined as a JavaScript-based library for manipulating documents based on data. D3 helps you bring data to life using HTML, SVG, and CSS. D3’s emphasis on web standards gives you the full capabilities of modern browsers without tying yourself to a proprietary framework, combining powerful visualization components and a data-driven approach to DOM manipulation.

Data visualization Interview Questions and answers.

Question 1) Define D3.js?D3.js is defined as a JavaScript-based library for manipulating documents based on data. D3 helps you bring data to life using HTML, SVG, and CSS. D3’s emphasis on web standards gives you the full capabilities of modern browsers without tying yourself to a proprietary framework, combining powerful visualization components and a data-driven approach to DOM manipulation.

Question 2) What does D3 stand for?

D3 stands for Data-Driven Documents

Question 3) Who developed D3.js?

Mike Bostock wrote D3.js based on his work during his Ph.D. studies at the Stanford Visualization Group. Mike worked at the The New York Times for a while and is now independently working on D3.js.

Question 4) Why use to D3.js?

You can use D3 js because

  • D3.js lets you to build the data visualization framework
  • D3.js focuses on binding data to DOM elements.
  • D3.js is written in JavaScript and uses a functional style which means you can reuse code and add specific functions to your heart’s content.

Question 5) How D3.js identify on which elements to operate?

D3.js uses CSS-style selectors to identify elements on which to operate.
Example:

d3.selectAll("p").style("color", "white");

Question 6) Explain selections in D3.js ?

D3 implements a declarative approach, operating on arbitrary sets of nodes called selections.
Also, Read Neo4j interview questions

Question 7) Explain, what is the use of “Enter” and “Exit” selection in D3.js ?

In D3.js “Enter” selection is used to create new nodes for incoming data and “Exit” selection is used eliminate outgoing nodes that are no longer required.

Question 8) List Type of sliders are available in D3.js?

There are 7 types of slider are available in D3.js, they are

  • Default slider
  • Slider with start value
  • Slider with slide event: 0
  • Slider with default axis
  • Slider with custom axis
  • Slider with min, max and step values
  • Vertical slider

Question 9) Explain transition in D3.js?

A transition is a selection-like interface for animating changes to the DOM. Instead of applying changes instantaneously, transitions smoothly interpolate the DOM from its current state to the desired target state over a given duration.

To apply a transition, select elements, call selection.transition and then make the desired changes.

For example:

d3.select("body")
  .transition()
    .style("background-color", "red");

Question 10) List the command to interpolate two objects in D3.js?

d3.interpolateObject(a,b) command is used to interpolate two objects in d3.js

Got a Questions? Share with us