Tuesday, 25 April 2017

React JS Interview Questions and Answers

React JS Interview Questions and Answers

Question: What is ReactJS?
React is front end library developed by Facebook.


Question: Why ReactJS is used?
React is used to handle the view part of Mobile application and Web application.


Question: Does ReactJS use HTML?
No, It uses JSX which is simiar to HTM.


Question: When ReactJS released?
March 2013


Question: What is current stable version of ReactJS?
Version: 16.2.0
Release on: November 28, 2017


Question: What is Repository URL of ReactJS?
https://github.com/facebook/react



Question: What are the life Cycle of ReactJS?
  1. Initialization
  2. State/Property Updates
  3. Destruction



Question: What are the feature of ReactJS?
  1. JSX: JSX is JavaScript syntax extension.
  2. Components : React is all about components.
  3. One direction flow: React implements one way data flow which makes it easy to reason about your app



Question: What are the Advantages of ReactJS?
  1. React uses virtual DOM which is JavaScript object. This will improve apps performance
  2. It can be used on client and server side
  3. Component and Data patterns improve readability.
  4. Can be used with other framework also.



Question: How to embed two components in One component?
import React from 'react';
class App extends React.Component {
   render() {
      return (
         <div>
            <Header/>
            <Content/>
         </div>
      );
   }
}

class Header extends React.Component {
   render() {
      return (
         <div>
            <h1>Header</h1>
         </div>
      );
   }
}

class Content extends React.Component {
   render() {
      return (
         <div>
            <h2>Content</h2>
            <p>The content text!!!</p>
         </div>
      );
   }
}

export default App;

Monday, 24 April 2017

Node.js - Global Objects

Node.js - Global Objects

Question: How to display the current filename?
console.log(__filename);
This gives you local filename of the current module.



Question: How to display the current directory name?
console.log(__dirname);
This gives you local dirname of the current module.



Question: How to call a function after 5 seconds?
For this, you can use a global function i.e setTimeout.
function helloFunction(){
   console.log( "Hello, World!");
}
/* helloFunction will call after 5 seconds*/
setTimeout(helloFunction, 5000);



Question: How to stop calling a function which was started with setTimeout?
For this, you can use a global function i.e clearTimeout.
function helloFunction(){
   console.log( "Hello, World!");
}
/* helloFunction will call after 5 seconds*/
var funcObj=setTimeout(helloFunction, 5000);

//stop funtion
clearTimeout(funcObj);



Question: How to call a function in every 7 seconds?
For this, you can use a global function i.e setInterval.
function helloFunction(){
   console.log( "Hello, World!");
}
/* helloFunction will call in every 7 seconds*/
setInterval(helloFunction, 7000);



Question: How to stop calling a function which was started with setInterval?
For this, you can use a global function i.e clearInterval
clearInterval(funcObj);



Question: What are different Console Methods to print info, error, warning etc?
  1. console.log: Prints to stdout with newline.
  2. console.error: Prints to stderr with newline.
  3. console.dir: Uses util.inspect on obj and prints resulting string to stdout.
  4. console.time: Mark the time
  5. console.timeEnd: Mark the time end
  6. console.trace: Print to stderr Trace



Question: What are Process Events?
The process object is a global object and can be accessed from anywhere.
process.on('exit', function(code) {   
   console.log('About to exit with code:', code);
});
console.log("Program Ended");



Question: What are different the Process Events?
  1. exit
  2. beforeExit
  3. uncaughtException
  4. Signal Events