javascript-interview-questions (Part- 2)

What is JavaScript?
The JavaScript is most popular scripting languages and it developed by Netscape and used to develop the client side web applications.

Is JavaScript Case Sensitive?
Yes! JavaScript is a case sensitive because a function “str” is not equal to “Str”.

What Is the Type of JavaScript?

There are different of Type as given below.

1.      String, 

2.      Number,

3.      Boolean,

4.      Function,

5.      Object,
6.      Null,
7.      Undefined etc.

What Types of Boolean Operators in JavaScript?
There are three types of Boolean operators as given below.
1.      AND (&&) operator, 
2.      OR (||) operator and 
3.      NOT (!) Operator

What Is the difference Between “==” and “===”?
The double equal “==” is an auto-type conversion and it checks only value not type.
The three equal “===” is not auto-type conversion and it check value and type both.

The example looks like–

if(1 == "1")

//Its returns true because it's an auto-type conversion and it checks only value not type.

if(1 === "1")//Its returns false because it's not auto-type conversion and it check value and type both.

if(1=== parseInt("1"))// its returns true.
// alert(0 == false); // return true, because both are same type.
// alert(0 === false); // return false, because both are of a different type.
// alert(1 == "1"); // return true, automatic type conversion for value only.

// alert(1 === "1"); // return false, because both are of a different type.
// alert(null == undefined); // return true.
// alert(null === undefined); // return false.
// alert('0' == false); // return true.
// alert('0' === false); // return false.
// alert(1=== parseInt("1")); // return true.

What Is an Object?

The object is a collection of properties and the each property associated with the name-value pairs. The object can contain any data types (numbers, arrays, object etc.)

The example as given below –
var myObject= {empId : “001”, empCode :X0091”};

In the above example, here are two properties one is empId and other is empCode and its values are “001” and “X0091”.

Types of creating an object
1.      Object literals
2.      Object constructor

Object Literals: This is the most common way to create the object with object literal and the example as given below.

The empty object initialized using object literal i.e.
var emptyObj = {};

This is an object with 4 items using object literal i.e.
var emptyObj ={
empCode: “X0091”,
empDetail : function(){

Object Constructor: The second way to create object using object constructor and the constructor is a function used to initialize new object. 

The example as given below -
var obj = new Object();

Obj.empAddressDetai = function(){
console.log(“HiI am Suraj”);

What Is Scope Variable in JavaScript?
The scope is set of objects, variables and function and the JavaScript can have global scope variable and local scope variable.

The global scope is a window object and it’s used out of function and within the functions.
The local scope is a function object and it’s used within the functions.

The example for global scope variable -
var gblVar = "Suraj";

function getDetail() {

And other example for global -
function demoTest() {
      x = 20;
console.log(x); //output is 20

The example for local scope variable -
function getDetail() {
     var lclVar = "Suraj K";
     console.log(lclVar );

And other example for local -
function demoText() {
    var x = 15;
console.log(x); //undefined

What Is an Associative Array in JavaScript?

The array with name indexes are called associative array and the associative array is provide a ways to store the information.

How To Achieve Inheritance in JavaScript?

What Is typeof Operator?
The typeof operator is used to find the type of variables.

The example as given below -
typeof "Anil Singh"   // Returns string
typeof 3.33           // Returns number
typeof true          // Returns Boolean
typeof { name: 'Anil'age: 30 } // Returns object
typeof [10203040// Returns object

What Is a Public, Private member in Javascript.

Fist I am creating a constructor class and trying to achieve the public and private variables and detail as given below –

function myEmpConsepts() { // This myEmpConsepts is a constructor  function.
var empId = "00201"//This is a private variable.
this.empName = "Suraj K"//This is a public variable.

this.getEmpSalary = function () {  //This is a public method
console.log("The getEmpSalary method is a public method")

//This is an instance method and its call at the only one time when the call is instantiate.
myEmpConsepts.prototype.empPublicDetail = function () {
console.log("I am calling public vaiable in the istance method :" + this.empName);
console.log("I am calling private vaiable in the istance method :" + this.empId);

var _obj= new myEmpConsepts();


I am calling public vaiable in the istance method : Suraj K
I am calling private vaiable in the istance method : undefined

How to Add/Remove Properties to Object in run-time in JavaScript?
I am going to explain by example for add and remove properties from JavaScript objects as give below.

//This is the JSON object.

var objectJSON = {

id: 1,

name: "Anil Singh",

dept: "IT"


This example for add property -
//This is used to add the property.
objectJSON.age = 30;

console.log(objectJSON.age); //The result is 30;

//This is the JSON object.
var objectJSON = {
id: 1,
name: "Anil Singh",
dept: "IT",
age: 30

This example for delete property -
//This is the process to delete

delete objectJSON.dept;

Why Never Use New Array in JavaScript?

We have some fundamental issues with new Array () the example in detail for array constructor function as given below.
When Array Have more the one Integer?
var newArray = new Array(1020304050);
console.log(newArray[0]); //returns 10.
console.log(newArray.length); //returns 5.

When Array Have Only One Integer?
var newArray = new Array(10);
console.log(newArray[0]); //returns undefined
console.log(newArray.length); //returns 10 because it has an error "array index out of bound";

//This is the fundamental deference to need to avoid the new array ();

What is eval() and floor() functions in JavaScript?

The eval() function used in execute an argument as expression or we can say that evaluate a string as expression and it used to parse the JSON.

The example over eval() function as given below -
var x = 14;
eval('x + 10'); //The output is 24.

Another over eval() function example -
eval('var myEval = 10');
console.log(myEval); // The output is 10.

The floor () function is a static method of Math and we can write as Math.floor() and used to round the number of downwards i.e.

Math.floor(1.6);//The output is 1.

What is join() and isNaN() functions in JavaScript?
The is join() function used to join the separator in the array.

Syntax - 

The example as given below -
var alfabets = ["A""B""C""D"];

//Join without seperator
var result1 = alfabets.join();//The output is A B C D.

//Join with seperator.
var result2 = alfabets.join(','); //The output is A, B, C, D.

The isNaN() function is used to check the value is not-a-number.

The example as given below -
var var1 = isNaN(-1.23);//The output is false.
var var2 = isNaN(3);//The output is false.
var var3 = isNaN(0);//The output is false.
var var3 = isNaN("10/03/1984"); //The output is true.

What Is Function Overloading in JavaScript?

There is no real function overloading in JavaScript and it allows passing any number of parameters of any type.

You have to check inside the function how many arguments have been passed and what is the type arguments using typeof.

The example for function overloading not supporting in JavaScript as gives below -
function sum(ab) {
    alert(a + b);
function sum(c) {
sum(3);//The output is 3.
sum(24);//The output is 2.

In the JavaScript, when we write more than one functions with same name that time JavaScript consider the last define function and override the previous functions. You can see the above example output for the same.

What Is Prototype in JavaScript?
The prototype is a fundamental concept of JavaScript and its must to known JavaScript developers.

All the JavaScript objects have an object and its property called prototype and its used to add and the custom functions and property.

The example without prototype as given below -

var employee = function () {

//This is a constructor function.


//Crate the instance of above constructor function and assign in a variable

var empInstance = new employee();
empInstance.deportment = "IT";

console.log(empInstance.deportment);//The output of above is IT.

//The example with prototype as given below-
var employee = function () { //This is a constructor  function.}

employee.prototype.deportment = "IT";//Now, for every instance employee will have a deportment.

//Crate the instance of above constructor functions and assign in a variable
var empInstance = new employee();
empInstance.deportment = "HR";

console.log(empInstance.deportment);//The output of above is IT not HR.

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.

How Promises Work
A promise is an object which can be returned synchronously from an asynchronous function. It will be in one of 3 possible states:
  1. Fulfilled: onFulfilled() will be called (e.g., resolve() was called)
  2. Rejected: onRejected() will be called (e.g., reject() was called)
  3. Pending: not yet fulfilled or rejected


Post a Comment


ADFS (1) ADO .Net (2) Ajax (1) Angular (1) Angular Js (17) Angular2 (28) ASP .Net (14) Authentication (1) Azure (1) Breeze.js (1) C# (50) CD (1) CI (2) CloudComputing (1) CMS (1) CSS (2) Design_Pattern (3) DevOps (4) DI (4) Dotnet (22) Entity Framework (3) ExpressJS (4) Html (3) IIS (1) Javascript (6) Jquery (8) Lamda (3) Linq (11) Mongodb (1) MVC (50) NodeJS (7) RDLC (1) Report (1) SDLC (1) Sql Server (30) SSIS (3) SSO (1) SSRS (2) UI (1) WCF (13) Web Api (11) Web Service (1) XMl (1)