Full Stack Interview Questions: Core Javascript



1. What is JavaScript?


JavaScript is a full stack language that is it is used at client side as well as server side.


It is one of the language which is used in both desktop as well as mobile platform.


It has become the first choice of most of the programmers today as it is easy to learn.


It is generally an Object based Programming Language.



2. What is  the differences between Java and JavaScript?


Java and Javascript are completely different languages. They are fully independent programming languages.


Java is object Oriented programming language while Javascript is Object based programming language.


Earlier javascript was not a complete language because it was used at client side only but not its introduction on the server has made it a complete programming language. Moreover it  has become more popular than Java among the young coders. 



3. What are the primitive data types in JavaScript?


Following are the JavaScript Data types:


Number

String

Boolean

Object

Undefined



4. What is the use of isNaN function?


isNan is a function used to check wheather an argument is a number or not.


It returns true if the argument is not a number otherwise it returns false.



5. Between JavaScript and an ASP script, which is faster?


JavaScript is faster.


If you execute javascript in client side then it will be definately faster than ASP script as it executes on server.


Also on server also Javascript code executes somewhat faster that ASP script.




6. What is negative infinity and what is its type?


-1/0 = -Infinity


It is what you get when you diving any negative number with 0.


It's type is NaN.



7. Who developed Javascript?


Brendan Eich  at Netscape(his Company)



8. What is the difference between undeclared and undefined variables?


Undeclared variables: Variables that are not even declared and used. On using they will throw error as "Variable is not defined at <anonymous>....."


eg.


      var b =10;


      var c = a+b; //a is not declared



Undefined variables:  Variables that are declared but never assigned any value. On using them it will return undefined.




    eg.


       var a;


       console.log(a); //undefined

   

   


9. How to add elements dynamically with Javascript?


<script>


             var text = document.createTextNode("Water");                                                   

document.getElementById("first").appendChild(text);


</script>


<p id="first"></p>



10. What are global variables? Where to use them and where to avoid them?


Variables that are accessible to the whole program everywhere is called a Global variable.


To declare a global variable just omit the word var.


It should be used where  a particular value is used in more than 1 independant functions in the program.


It should be avoided where value is only used in a single function.



11. What are different  Popup boxes  in Javascript?


There are 3 popup boxes in javascript:


Alert   


syntax: alert("Any message");


Confirm


syntax: confirm("Any message");


Prompt


syntax: prompt(text,defaulttext)



12. What is prompt box in javascript?


It is a type of alert box where user can input text or number and either continue or cancel.


eg.


         prompt("Do you want to Continue?");

 


13. What is 'this' keyword in JavaScript?


'This'  refers to the object to which it belongs.


It can have different value on the context where it is used.


for eg.


In method : this refers to the owner object


If Alone : this refers to the global object


In Function : this refers to the global object



14. Please explain equality operators in JavaScript?


There are mainly four equality operator in javascript:


Equality ( == )


InEquality ( != )


Strict Equality ( === )


Strict InEquality ( !== )


    


15. What are anonymous functions in JavaScript ?


functions defined without name are called anonymous function in javascript.


eg.


  var a = function () {


                      console.log("hello");


    }


16. What is  local and global scope in JavaScript ?


In Javascript there are 2 scopes for the variable:

* Local

* Global

Variable inside a function have local Scope and are not accessible outside the function.

Variable outside the function have global Scope and can be accessed inside a function also.


class ScopeVar {

    var test = "test";   //global scope

function local1{

var a =10;  //local 

console.log(test);

}

console.log(a); //return error as it is outside local scope

}

   



17. What is  settimeout function in JavaScript?


This function will execute a particular function at a particular time.

syntax:

setTimeout(function, milliseconds, param1, param2, ...)


eg: 

settimeout(function(){

console.log("hello");

},1000);


18. What is  setInterval function in JavaScript?


This function will execute a particular function at a particular interval of time.

syntax:

setTimeout(function, milliseconds, param1, param2, ...)


eg: 

settimeout(function(){

console.log("hello");

},1000);

19. What is the difference between setTimeout and setInterval in javascript?


setTimeout will be executed only once while setInterval will be executed continuosly at a particular interval until program completes.



20.What is the drawbacks of Timer like setTimeout or setInterval if any?


Timers are operated within a single thread, and thus events might queue up, waiting to be executed.


21. Which to use comments in Javascript?


// for Single line comments and


/* Multi


Line


Comment


*/



22. How to Submit a form using javascript?


document.form[0].submit();



23. Is there automatic type conversion in javascript?


Yes there is automatic type conversion in Javascript.



24. How to update style of element in Javascript ?


document.getElementById("myText").style.fontSize = "20?;




25. How to update style of element in Javascript ?



document.getElementById("myText").className = "anyclass";



26. What are the various loops in Javascript?


Various Loops in Javascript are : 

For

While

do-while loops

27. What is called Variable typing in Javascript?


Variable typing means the variable gets the type to which  the value is stored in it.


for example


i = 10; //here type of i is int

i = "string"; // in the next line type of i is string


This is called variable typing


28. How to convert the string to integer in Javascript?


parseInt() function is user to convert string to integer.


29. Explain the difference between "==" and "==="?


"==" : It checks only for value and without comparing their types.

"===" : It checks for both value and type of the variable


for eg.

1 == "1" : is true

1 === "1" : is false


30. What would be the result of 6+1+"8"?


First 6 and 1 are added as they are integers.

Now since 8 is a string so it is concatenated with the result of addition that is 7.

Hence the final output will be 78.



31. How to find the operating system on the client machine?


To detect the client machine operating system,use

navigator.appversion



32. What is NULL in Javascript?


The  null value  represents the absence of any object value. 

It is one of the JavaScript's primitive value.


Always remember


typeof null is "object"


33. What is the use of delete operator?


delete keyword deletes both key and value of an object.


for eg.


var student= {age:20, batch:"ABC"};

delete student.age;


34. What is undefined in Javascript?


undefined means :

* Either the Variable is not exist

* Variable exist but no value is assigned

* Property does not exist




35. How to force load another page using javascript?


To force load another page:


<script language="JavaScript" type="text/javascript" >


<!-- location.href="http://google.com"; //-->

</script>



36. Difference between alert and confirm box in javascript


alert box : only single button OK.

confirm box : two buttons namely OK and Cancel.



37. What are Cookies in JavaScript?


Cookies are generally small text files which are stored in our system.


It gets created when a user visits a website.


Cookies are different from Sessions as they get stored on the client system rather than Server.


for eg.


When you logged in on Google the cookie get stored in your system which contains the authentication information.


On your subsequent request this cookie will be passed to the server and the server will authenticate you on the basis of this cookie.



38. What is the use of pop() method in javascript?


It is used to remove topmost  element from the array.


Example:


var cloths = ["Shirt", "Pant", "TShirt"];

cloths.pop();


console.log(cloths); // Shirt,Pant are left only as TShirt has been deleted.


39. What is the use of push() method in javascript?


It is used to add element to the top of the array.


Example:


var cloths = ["Shirt", "Pant"];

cloths.push("Shocks");


console.log(cloths); // Shirt,Pant,Shocks 



40. What is break in Javascript?


Break statement exits from the current loop.


eg. 

  for(var i=0; i< 10;i++){

   if(i > 5)

   break;

   console.log(i);

   

   }

   

  output:  1234


41. What is continue in javascript?


Continue statement continues with next statement of the loop.

eg. 

  for(var i=0; i< 10;i++){

   if(i > 5)

   continue;

   console.log(i);

   

   }

   

  output:  12346789



42. How to find the type of a variable in javascript.


typeof function is used to find out the type of variable in javascript.


for eg.


  typeof 10; //number



43. How to handle exception handling in Javascript ?


We can use try -- catch -- finally to handle exception in javascript.


eg. 

   try{

       //code

} catch(exp){

    //code to catch exception

}finally{

    //this code will be executed everytime

}



44. How to print text on the screen using javascript?


document.write("Welcome") is used to print text on the screen.


This will remove all the html from the page. So handle this with care.



45. What is the use of blur function?


Blur function is used to remove the focus from the specified object.



46. How many types of errors occur in Javascript ?

There are mainly 3 types of errors in javascript:

* Load Time errors : These error occur due to incorrect syntax. It comes during the webpage load.

* Run Time errors : Errors that comes due to incorrect command. They occur during the website runtime.

* Logical errors : These errors are the toughest error and are generally something which are hard to find. They basically occurs due to wrong logic implementation.
for eg. using - instead of + in addition function.

47. What is unshift operation in javascript ?
unshift is an array operation which is used to add elements at the beginning of the array.
It returns the updated length of the array.

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.unshift("Lemon","Pineapple");

console.log(fruits); // ["Lemon","Pineapple","Banana", "Orange", "Apple", "Mango"]

48. How to assign properties to javascript object ?

You can assign the property to object by two ways:
* Array way:
obj['age'] = 12;

OR

* Dot notation:
obj.age = 12;
49. What is strict mode in javascript and how to enable it ?

Strict mode ensures that the code that is supported in maximum browers should be there and the code or functions which are introduced in the new upcoming javascript will throw errors.
It can be enabled by adding the literal:
"use strict"
This should be placed at the top of the block

for eg.
     function myfunction() {
"use strict";
var v = "This function is under strict mode";
}


50. What is the 'Strict' mode in JavaScript and how can it be enabled?

Strict Mode adds certain compulsions to JavaScript. Under the strict mode, JavaScript shows errors for a piece of codes, which did not show an error before, but might be problematic and potentially unsafe. Strict mode also solves some mistakes that hamper the JavaScript engines to work efficiently.

Strict mode can be enabled by adding the string literal "use strict" above the file. This can be illustrated by the given example:

function myfunction() {
    "use strict";
     var v = "This is a strict mode function";
}


51. What is the way to get the status of a CheckBox?

document.getElementById('checkbox1').checked;

you can use it in the  function as :

if(document.getElementById('checkbox1').checked){
alert("checkbox is checked");
}else{
alert("checkbox is not checked");
}

Comments :

  1. The field of software development is vast and varied. A trying student, in the field of software development, must chose carefully what type of software he ought to specialize in. One of the areas of specialization, where great career opportunities exist is in MEAN Stack.
    For More Info: MEAN Stack Institute in Gurgaon

    ReplyDelete

Post a Comment