JavaScript developed by Netscape. JS is a client side as well as a server-side scripting language. It is interpreted programming language as well with object orientated capabilities.
1. How do you create a class in JavaScript?
Answer – There are multiple ways you can create a class in JS. For example
Method 1 – Using functions
// This is a class name
function Flat(aptName, location){
// You can define object properties
this.aptName = aptName;
this.location = location;
this.getLocation = getLocationInfo
}
// The method can be defined as
function getLocationInfo{
return “The location is “ + this.location;
}I
// You can even define function of a class like this
Flat.prototype.getFlatInfo = function() {
alert (“The apartment name is” + this.aptName + “ and the location is “ + this.location = location);
// Instantiate new object of Flat class
var myFlat = new Flat(“Manjeera”, “Kukatpally”);
// Invoke methods like this
alert myFlat.getLocationInfo();
Method 2 – Using object literals
Var Flat = {
this.aptName = “manjeera”;
this.location = “kukatpally”;
this.getLocation = function() {
return “The location is “ + this.location;
}
}
Apart from using functions, and object literals, you can use object constructor as well to create JavaScript class.
2. What is the difference between ‘==’ and ‘===’?
Answer – ‘==’ checks for equality only
‘===’ checks for equality and type
For example
false == 0 returns TRUE
false === 0 returns FALSE
3. What is isNan? Give example?
Answer – This would return true of the argument is not a number. For example
isNaN(23) returns false
isNaN(“2/3/2017”) returns true
4. What are the difference comments available in JavaScript?
Answer – There are two types of comments available in JavaScript
A. Single line comments
// This is a single line comment
B. Block comments
/*
This can be used
For block comments
..
*/
5. What are the types used by JavaScript?
Answer – There are six types used in Java Script
Boolean (True and False)
Null (null)
Undefined (undefined)
Number (Integers, floating etc.)
String
Object (Objects, Array, Functions etc.)
6. Is JavaScript a case sensitive?
Answer – Yes, JavaScript is case-sensitive.
7. How can you create an object in JavaScript
Answer – You can use object literal as shown below
var student = {
name: “Sandeep”,
age: 36
};
Alternatively, you can use below (As explained in question number 1)
var myFlat = new Flat(“Manjeera”, “Kukatpally”);
8. Does JavaScript support exception handling?
Answer – Yes, it does support exception handling by means of try and catch. It supports try, catch, finally, throw etc. keywords to handle exceptions.
9. What is the difference between break and continue?
Answer – Break statement causes program control to exit from the loop.
The continue statement causes program control to continue with next statement.
10. What is the primary difference between ViewState and SessionState?
Answer – ViewState represents a page in session while SessionState is specific to user specific data which can be accessed all across in the web application.