InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
When Using The Addeventlistener() Method To Create A Click-handler For A Dom Element, What Is The Value Of “this” Inside Of The Callback You Specify? |
|
Answer» The DOM ELEMENT that was CLICKED. The DOM element that was clicked. |
|
| 2. |
What Are Two Ways In Which The Variable “foo” Can Be Assigned To An Empty Object? |
| Answer» | |
| 3. |
What Is Important To Remember About The Last Property’s Value In A Javascript Object Literal? |
|
Answer» The last PROPERTY’s value should NOT be followed by a comma. Most browsers will LET you GET away with it if you FORGET, but Microsoft Internet Explorer will complain about the extra comma. The last property’s value should NOT be followed by a comma. Most browsers will let you get away with it if you forget, but Microsoft Internet Explorer will complain about the extra comma. |
|
| 4. |
What Is The Difference Between Using Dot Notation And Bracket Notation When Accessing An Object’s Property? |
|
Answer» If using dot NOTATION, the property MUST be a STRING and refer to a property that EXISTS. When using bracket notation, any valid JavaScript EXPRESSION that produces a value can be used inside the brackets, such as a variable or an an array element. If using dot notation, the property must be a string and refer to a property that exists. When using bracket notation, any valid JavaScript expression that produces a value can be used inside the brackets, such as a variable or an an array element. |
|
| 5. |
Which Object.property Combination Provides A Reference To The Protocol Used To View The Current Web Page? |
|
Answer» location.protocol location.protocol |
|
| 6. |
What Is The Name Of The Object That Refers To The Application Used To View A Web Page? |
|
Answer»
The object returned by the document.getElementsByTagName() method is an array. False, The object returned by the document.getElementsByTagName() method is an “HTMLCollection”. This is an array-like object that has a “length” PROPERTY, can be ENUMERATED, but is not an actual JavaScript array. The “navigator” object The object returned by the document.getElementsByTagName() method is an array. False, The object returned by the document.getElementsByTagName() method is an “HTMLCollection”. This is an array-like object that has a “length” property, can be enumerated, but is not an actual JavaScript array. |
|
| 7. |
An Object Literal Can Be Used To Create Private Variables? |
|
Answer» False. Only functions can be used in JAVASCRIPT to CREATE PRIVACY. False. Only functions can be used in JavaScript to create privacy. |
|
| 8. |
What Is The Difference Between A Constructor Function And A Non-constructor Function With Respect To The Word “this” ? |
|
Answer» In a non-constructor function, “this” REFERS to the GLOBAL context or if the function is a method, it refers to the object to which the method belongs. In the INSTANCE object that is RETURNED by a constructor function, “this” refers to the instance object itself. In a non-constructor function, “this” refers to the global context or if the function is a method, it refers to the object to which the method belongs. In the instance object that is returned by a constructor function, “this” refers to the instance object itself. |
|
| 9. |
In Javascript, Are Objects Passed By Reference Or By Value? |
|
Answer» In JAVASCRIPT, all OBJECTS are passed by REFERENCE. When you MAKE a change to a reference to an object, you change the actual object. Primitive TYPES are passed by value. In JavaScript, all objects are passed by reference. When you make a change to a reference to an object, you change the actual object. Primitive types are passed by value. |
|
| 10. |
Can A Javascript Constructor Return A Primitive Value (e.g. A Number Or A String)? |
|
Answer» No. A JAVASCRIPT constructor can only RETURN an OBJECT. When no return value is specified, it RETURNS an INSTANCE of itself. If an object is specified as the return value, then that object is the return value. If any value other than an object is specified as the return value, then it returns an instance of itself. No. A JavaScript constructor can only return an object. When no return value is specified, it returns an instance of itself. If an object is specified as the return value, then that object is the return value. If any value other than an object is specified as the return value, then it returns an instance of itself. |
|
| 11. |
Name Two Ways Two Change The Context Of A Javascript Method ? |
|
Answer» USE the call or apply METHODS, The call and apply methods can be used to specify the context of another method. VAR objectA = { Use the call or apply methods, The call and apply methods can be used to specify the context of another method. var objectA = { |
|
| 12. |
When You Create A Function Inside Of A Method, What Does The “this” Keyword Refer To When Used In That Function? |
|
Answer» The “window” object, Inside of a function, the “this” keyword ALWAYS refers to the window object. But when a funciton is a PROPERTY of on object, the “this” keyword always refers to the object that the function is a method of. var myObject = { color : "red", In the above example, the output to your JavaScript console should be:
The reason for the output is: The testThis function inside of the myObject.test method attempts to log the value of “this.color”. That function is NOT a method, it is just a function declaration, so “this” refers to the window object. In this code, the window object, does not have a “color” property, so “this.color” is undefined. Next, the testThis function inside of the myObject.test method compares, window to the “this” keyword (just to prove the previous point). Again, because the testThis function inside of the myObject.test method is NOT a method, it is a property of the window object, so “this” DOES equal the window object. Next, the myObject.test method attempts to log the value of “this.color”. Since the test metod is a property of the myObject object, and the myObject object has a property named “color”, the value of that property is LOGGED to the console. Next, the myObject.test method attempts to compares window to the “this” keyword. Since the test metod is a property of the myObject object, the “this” keywork refers to the myObject object, and the COMPARISON to the window object returns false. The “window” object, Inside of a function, the “this” keyword always refers to the window object. But when a funciton is a property of on object, the “this” keyword always refers to the object that the function is a method of. var myObject = { color : "red", In the above example, the output to your JavaScript console should be: The reason for the output is: The testThis function inside of the myObject.test method attempts to log the value of “this.color”. That function is NOT a method, it is just a function declaration, so “this” refers to the window object. In this code, the window object, does not have a “color” property, so “this.color” is undefined. Next, the testThis function inside of the myObject.test method compares, window to the “this” keyword (just to prove the previous point). Again, because the testThis function inside of the myObject.test method is NOT a method, it is a property of the window object, so “this” DOES equal the window object. Next, the myObject.test method attempts to log the value of “this.color”. Since the test metod is a property of the myObject object, and the myObject object has a property named “color”, the value of that property is logged to the console. Next, the myObject.test method attempts to compares window to the “this” keyword. Since the test metod is a property of the myObject object, the “this” keywork refers to the myObject object, and the comparison to the window object returns false. |
|
| 13. |
Once You Create An Object, You Can Add, Remove Or Change Properties Of That Object At Any Time? |
|
Answer» YES. We can add,remove or CHANGER PROPERTIES of CREATED object at any TIME. Yes. We can add,remove or changer properties of created object at any time. |
|
| 14. |
How Do You Determine If A Javascript Instance Object Was Created From A Specific Constructor Or Not? |
|
Answer» USE the INSTANCEOF OPERATOR. Use the instanceof operator. |
|
| 15. |
If You Omit The “var” Keyword When Creating A Variable In A Function, It Becomes A Property Of What Object? |
|
Answer» When omitting the “var” keyword, the variable you create becomes an “implied global”. But implied globals are not VARIABLES in a function. An implied global ACTUALLY becomes a property of the window OBJECT. Although the window object is considered the “global” scope, it is an object, and any variable DECLARED in the global scope (intentionally or otherwise), becomes a property of the window object. When omitting the “var” keyword, the variable you create becomes an “implied global”. But implied globals are not variables in a function. An implied global actually becomes a property of the window object. Although the window object is considered the “global” scope, it is an object, and any variable declared in the global scope (intentionally or otherwise), becomes a property of the window object. |
|
| 16. |
The Terms “scope” And “context” Refer To The Same Thing In Javascript ? |
|
Answer» FALSE, SCOPE pertains to the visibility of VARIABLES, and CONTEXT refers to the object to which a method belongs (which can be CHANGED by using call or apply). False, Scope pertains to the visibility of variables, and context refers to the object to which a method belongs (which can be changed by using call or apply). |
|
| 17. |
Why "self" Is Needed Instead Of "this" In Javascript? |
|
Answer» In this post, I am share the “Why self is needed instead of this in JavaScript?” and ALSO what is the advantage of using “var self = this;” var self = this; In the JavaScript, “self” is a pattern to maintaining a reference to the original “this” keyword and also we can say that this is a technique to HANDLE the events. RIGHT now, “self” should not be used because modern browsers provide a “self” as global VARIABLE (window.self). Example [“self” keyword is needed instead of “this”], var employee = function (name) { var self = this; In this post, I am share the “Why self is needed instead of this in JavaScript?” and also what is the advantage of using “var self = this;” var self = this; In the JavaScript, “self” is a pattern to maintaining a reference to the original “this” keyword and also we can say that this is a technique to handle the events. Right now, “self” should not be used because modern browsers provide a “self” as global variable (window.self). Example [“self” keyword is needed instead of “this”], var employee = function (name) { var self = this; |
|
| 18. |
What Are Different Two Ways Of Creating An Object? |
|
Answer» OBJECT LITERALS: This is the most common way to create the object with object literal. For Example: var emptyObj= {}; Object Constructor: It is way to create object using object constructor and the constructor is used to INITIALIZE new object. For Example: Var obj = new Object(); Global variable: A variable which can be variable from any where of the page. Following are different two ways. First Way Declare the JavaScript variable at the top of JavaScript code and out of function & OBJECTS. var globalVariable1 ='This is global variable 1' Object Literals: This is the most common way to create the object with object literal. For Example: var emptyObj= {}; Object Constructor: It is way to create object using object constructor and the constructor is used to initialize new object. For Example: Var obj = new Object(); Global variable: A variable which can be variable from any where of the page. Following are different two ways. First Way Declare the JavaScript variable at the top of JavaScript code and out of function & objects. var globalVariable1 ='This is global variable 1' |
|
| 19. |
What Are Different Data-types Of Javascript? |
|
Answer» FOLLOWING are different data-type in JavaScript. Following are different data-type in JavaScript. |
|
| 20. |
What Is Prototype In Javascript? |
|
Answer» The prototype is a fundamental concept of JavaScript and its must to known JavaScript developers. All the JavaScript objects has 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 () { //Create the instance of above constructor function and assign in a variable var empInstance = new employee(); 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.} The prototype is a fundamental concept of JavaScript and its must to known JavaScript developers. All the JavaScript objects has 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 () { //Create the instance of above constructor function and assign in a variable var empInstance = new employee(); 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.} |
|
| 21. |
What Is Function Overloading In Javascript? |
|
Answer» There is no real function overloading in JavaScript and it ALLOWS to pass 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 usingtypeof. The example for function overloading not supporting in JavaScript as give below. function sum(a, b) { 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. We can achieve using the several different techniques as give below
There is no real function overloading in JavaScript and it allows to pass 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 usingtypeof. The example for function overloading not supporting in JavaScript as give below. function sum(a, b) { 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. We can achieve using the several different techniques as give below |
|
| 22. |
What Is Javascript Hoisted? |
|
Answer» In the JAVASCRIPT, the variables can be used before declared, this kinds of mechanism is called Hoisted. It's a default behavior of JavaScript. You can EASILY understanding in the below example in detail. //The variable declaration LOOK like. var emp; //The declaration of a different variable name emp is hoisted but the value of emp is undefined. console.log(emp); //The output is undefined In the JavaScript, the variables can be used before declared, this kinds of mechanism is called Hoisted. It's a default behavior of JavaScript. You can easily understanding in the below example in detail. //The variable declaration look like. var emp; //The declaration of a different variable name emp is hoisted but the value of emp is undefined. console.log(emp); //The output is undefined |
|
| 23. |
What Is Closure In Javascript? |
|
Answer» While you create the JavaScript function within another function and the inner function freely access all the variable of OUTER function. i.e. function ourterFun(i) { The output will get 16 because innerFun() function can access to the argument "i" & variable "var1" but both are define in the outerFun() function that is closure. That means simply accessing variable OUTSIDE of your scope create a closure. // OR Other WAYS While you create the JavaScript function within another function and the inner function freely access all the variable of outer function. i.e. function ourterFun(i) { The output will get 16 because innerFun() function can access to the argument "i" & variable "var1" but both are define in the outerFun() function that is closure. That means simply accessing variable outside of your scope create a closure. // OR Other WAYS |
|
| 24. |
What Is Join() And Isnan() Functions In Javascript? |
|
Answer» The is join() function used to join the separator in the array. Syntax: myArray.join(mySeparator); The example as given below. var alfabets = ["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. The is join() function used to join the separator in the array. Syntax: myArray.join(mySeparator); The example as given below. var alfabets = ["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. |
|
| 25. |
What Is Eval() And Floor() Functions In Javascript? |
|
Answer» 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; 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. 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; 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. |
|
| 26. |
Why Never Use New Array In Javascript? |
|
Answer» 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? When array have only one integer? 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? When array have only one integer? |
|
| 27. |
How To Extending Built-in Objects In Javascript? |
|
Answer» JavaScript support BUILT-in objects which USE to develop the flexibility of JavaScript. The built in object are date, string, MATH, array and object. It's very similar to other languages and its available in the window content and WOK independently when brewers are loaded. Example as give below JavaScript support built-in objects which use to develop the flexibility of JavaScript. The built in object are date, string, math, array and object. It's very similar to other languages and its available in the window content and wok independently when brewers are loaded. Example as give below |
|
| 28. |
How To Add/remove Properties To Object In Run-time In Javascript? |
|
Answer» I am going to explain by example for add and remove properties from JavaScript OBJECTS as GIVE below. This example for DELETE property. I am going to explain by example for add and remove properties from JavaScript objects as give below. This example for delete property. |
|
| 29. |
Who To Create The Namespace In Javascript? |
|
Answer» Please SEE the below example for how to create the namespace in JavaScript. //Create the namespace. Please see the below example for how to create the namespace in JavaScript. //Create the namespace. |
|
| 30. |
What Is Public, Private And Static Variables In Javascript? |
|
Answer» I am GOING to explain like strongly type object oriented language (OOPs) like(C#,C++ and java etc.). Fist I am creating a conductor class and trying to achieve to declare the public, private and static variables and detail as given below. FUNCTION myEmpConsepts() { // This myEmpConsepts is a constructor function. I am going to explain like strongly type object oriented language (OOPs) like(C#,C++ and java etc.). Fist I am creating a conductor class and trying to achieve to declare the public, private and static variables and detail as given below. function myEmpConsepts() { // This myEmpConsepts is a constructor function. |
|
| 31. |
What Is Typeof Operator? |
|
Answer» The typeof operator is USED to FIND the type of variables. The typeof operator is used to find the type of variables. |
|
| 32. |
How To Achieve Inheritance In Javascript? |
|
Answer» In the JavaScript, we can implement the INHERITANCE using the some alternative WAYS and we cannot define a class keyword but we create a constructor function and using new keyword achieve it. The some alternative ways as given below.
Pseudo classical inheritance is the most popular way. In this way, create a constructor function using the new operator and add the members function with the help for constructor function prototype. The prototype based programming is a technique of object oriented programming. In this mechanism we can reuse the EXITING OBJECTS as prototypes. The prototype inheritance also know as prototypal, classless or instance based inheritances. The Inheritance example for prototype based as given below // Create a helper function. var child = Object.create(parent); In the JavaScript, we can implement the inheritance using the some alternative ways and we cannot define a class keyword but we create a constructor function and using new keyword achieve it. The some alternative ways as given below. Pseudo classical inheritance is the most popular way. In this way, create a constructor function using the new operator and add the members function with the help for constructor function prototype. The prototype based programming is a technique of object oriented programming. In this mechanism we can reuse the exiting objects as prototypes. The prototype inheritance also know as prototypal, classless or instance based inheritances. The Inheritance example for prototype based as given below // Create a helper function. var child = Object.create(parent); |
|
| 33. |
Where To Use The Associate Array? |
|
Answer» I am going to EXPLAIN the associate array over the database table COLUMNS. A table have some columns and its type. i.e. The empName as text type, empAge as number type and enpDOB as date type. If we need to find the type of a COLUMN that time we can create the associate array. i.e. VAR empDetailType = new Array(); I am going to explain the associate array over the database table columns. A table have some columns and its type. i.e. The empName as text type, empAge as number type and enpDOB as date type. If we need to find the type of a column that time we can create the associate array. i.e. var empDetailType = new Array(); |
|
| 34. |
What Is Array?what Is Associative Arrays In Javascript? |
|
Answer» Array is a collection of index items and it is a number indexes. The array with name indexes are called associative array and the associative array is provide a ways to STORE the information. The number index array example as given below var USERS = new Object(); The name index array example as given below Array is a collection of index items and it is a number indexes. The array with name indexes are called associative array and the associative array is provide a ways to store the information. The number index array example as given below var users = new Object(); The name index array example as given below |
|
| 35. |
What Is Scope Variable In Javascript? |
Answer»
The EXAMPLE for global scope variable var gblVar = "Anil Singh"; console.log(gblVar); and other example for global The example for local scope variable var gblVar = "Anil Singh"; and other example for local The example for global scope variable var gblVar = "Anil Singh"; console.log(gblVar); and other example for global The example for local scope variable var gblVar = "Anil Singh"; and other example for local |
|
| 36. |
What Is The Difference Between “==” And “===”? |
|
Answer» 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 REAL example as given below: if(1 == ”1”) // Its returns true because it's an auto-type conversion and it checks only value not type. 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 real example as given below: if(1 == ”1”) // Its returns true because it's an auto-type conversion and it checks only value not type. |
|
| 37. |
What Types Of Boolean Operators In Javascript? |
|
Answer» There are three TYPES of Boolean operators as GIVEN below. There are three types of Boolean operators as given below. |
|
| 38. |
What Is The Type Of Javascript? |
|
Answer» There are different of TYPE as given below. There are different of Type as given below. |
|
| 39. |
Is Javascript Case Sensitive? |
|
Answer» Yes! JAVASCRIPT is a case SENSITIVE because a function STR is not EQUAL to Str. Yes! JavaScript is a case sensitive because a function str is not equal to Str. |
|