1.What is JavaScript?JavaScript is a lightweight, interpreted programming language with object-oriented capabilities that allows you to build interactivity into otherwise static HTML pages. 2.Name some of the JavaScript features.?Following are the features of JavaScript − 3.What are the advantages of using JavaScript?Following are the advantages of using JavaScript − 4.What are disadvantages of using JavaScript?We can not treat JavaScript as a full fledged programming language. It lacks the following important features − 5.Is JavaScript a case-sensitive language?Yes! JavaScript is a case-sensitive language. This means that language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters. 6.How can you create an Object in JavaScript?JavaScript supports Object concept very well. You can create an object using the object literal as follows −
var emp = {
name: "aarif", age:13 }; 7.How can you read properties of an Object in JavaScript?You can write and read properties of an object using the dot notation as follows
// Getting object properties
emp.name // ==> aarif emp.age // ==> 30 // Setting object properties emp.name = "Naushaad" emp.age = 28 8.How can you create an Array in JavaScript?You can define arrays using the array literal as follows −
varx = [];
var y = [1,2, 3, 4, 5]; 9.How to read elements of an array in JavaScript?An array has a length property that is useful for iteration. We can read elements
of an array as follows −
var x = [1,2, 3, 4, 5];
for (var i = 0; i < x.length; i++) { // Do something with x[i] } 10.What is a named function in JavaScript?How to define a named function?A named function has a name when it is
defined. A named function can be defined using function keyword as follows −
function named(){ // do some stuff here}
11.How many types of functions JavaScript supports?A function in JavaScript can be either named or anonymous. 12.How can you get the type of arguments passed to a function?Using typeof operator, we can get the type of arguments passed to a function.
function func(x){
console.log(typeof x, arguments.length); } func(); //==> "undefined", 0func(1); //==> "number", 1 func("1", "2", "3"); //==> "string", 3 13.How can you get the total number of arguments passed to a function?Using arguments.length property, we can get the total number of arguments
passed to a function. For example −
function func(x){
console.log(typeof x, arguments.length); } func(); //==> "undefined", 0 func(1); //==> "number", 1 func("1", "2","3"); //==> "string", 3 14.How can you get the reference of a caller function inside a function?The arguments object has a callee property, which refers to the function you're
inside of. For example −
function func()
{ return arguments.callee ; } func(); // ==> func 15.What is the purpose of 'this' operator in JavaScript?JavaScript famous keyword this always refers to the current context. 16.What are the valid scopes of a variable in JavaScript?The scope of a variable is the region of your program in which it is defined. 17.Which type of variable among global and local, takes precedence over other if names are same?A local variable takes precedence over a global variable with the same name. 18.What is callback?A callback is a plain JavaScript function passed to some method as an argument or option. Some callbacks are just events, called to give the user a chance to react when a certain state is triggered. 19.What is closure?Closures are created whenever a variable that is defined outside the current scope is accessed from within some inner scope. 20.Give an example of closure?Following example shows how the variable counter is visible within the create,
increment, and print functions, but not outside of them −
function create()
{ var counter = 0; return { increment: function() { counter++; }, print: function() { console.log(counter); } }} var c = create(); c.increment(); c.print(); // ==> 1 |