Tuesday, January 29, 2019

Basic Interview Questions


Javascript


  1. What is a closure ?
    • Closure is a feature in javascript where an inner function have access to outer functions variables - scope chain.
    • Example
      • function outer() {
           var b = 10;
           function inner() {
                
                 var a = 20; 
                 console.log(a+b);
            }
           return inner;
        }
  2. What is a prototype ?
    • All JavaScript objects inherit properties and methods from a prototype:
    • Date objects inherit from Date.prototype
    • Array objects inherit from Array.prototype
    • Person objects inherit from Person.prototype
    • The Object.prototype is on the top of the prototype inheritance chain:
    • Date objects, Array objects, and Person objects inherit from Object.prototype.
  3. what is hoisting ?
    1. https://www.sitepoint.com/back-to-basics-javascript-hoisting/

Node.js

  1. What is server side Javascript?
    • Node.js is a server side JavaScript built on Google’s V8 JavaScript engine. It is an open source programming language that was developed by Ryan Dahl in 2009. It allows us to build scalable network applications, and is very fast when compared with other server side programming languages because it is written in C and the non-blocking I/O model. It is currently sponsored by Joynet, a software company specialising in high performance container native infrastructure. Node.js can run on Linux, Sun OS, Mac OS X and Windows platforms.
      The steps below explain the difference between blocking code and non-blocking code models.
      In the blocking code model, the steps are:
      1. Read a file
      2. Process the file
      3. Print the result
      4. Perform the next function
      The steps in the non-blocking code model are:
      1. Read a file
      1.1. When file reading is completed, process it
      1.1.1. When the processing is completed, print the result
      2. Perform the next function
  • What is non-block io model?
    • The steps in the non-blocking code model are:
      1. Read a file
      1.1. When file reading is completed, process it
      1.1.1. When the processing is completed, print the result
      2. Perform the next function
  • What is meant by event driven programming?
    • An event-driven program is one that largely responds to user events or other similar input. The concept of event-driven programming is an important one in application development and other kinds of programming, and has spawned the emergence of event handlers and other resources.
  •  What is a promise?
    • A promise is an object that may produce a single value some time in the future: either a resolved value, or a reason that it’s not resolved (e.g., a network error occurred). A promise may be in one of 3 possible states: fulfilled, rejected, or pending. Promise users can attach callbacks to handle the fulfilled value or the reason for rejection.
    • save()
        .then(handleSuccess)
        .catch(handleError)
      ;
  • The types of indexes are:

    1. Clustered: Clustered index sorts and stores the rows data of a table / view based on the order of clustered index key. Clustered index key is implemented in B-tree index structure.

    2. Nonclustered: A non clustered index is created using clustered index. Each index row in the non clustered index has non clustered key value and a row locator. Locator positions to the data row in the clustered index that has key value.

    3. Unique: Unique index ensures the availability of only non-duplicate values and therefore, every row is unique.

    4. Full-text: It supports is efficient in searching words in string data. This type of indexes is used in certain database managers.

    5. Spatial: It facilitates the ability for performing operations in efficient manner on spatial objects. To perform this, the column should be of geometry type.

    6. Filtered: A non clustered index. Completely optimized for query data from a well defined subset of data. A filter is utilized to predicate a portion of rows in the table to be indexed.
  • SELECT MAX(col) FROM table WHERE col NOT IN (SELECT MAX(col) FROM table);
  • Benefits of NoSQL over SQL.
    • NoSQL database features
      Schema-agnostic: NoSQL helps to store information without doing up‐front schema design.
      Nonrelational: The information in NoSQL is stored in the form aggregate. A single record store every information about the transaction, including the delivery address.
      Commodity hardware: NoSQL database is cheap and adding lower cost servers allows NoSQL databases to handle and scale more data.
      Highly distributable: NoSQL uses the powerful, efficient architecture instead of the expensive monolithic architecture. The cluster of servers in NoSQL database can be used to hold a single large database.