Java Script Interview Question and Answer

1. Explain JavaScript?
JavaScript is a client-side as well as server side scripting language that can be inserted into HTML pages and is understood by web browsers. JavaScript is also an Object Oriented Programming language.

2. What is ‘this’ keyword in JavaScript?
‘This’ keyword refers to the object from where it was called. In JavaScript, the thing called this, is the object that “owns” the JavaScript code. The value of this, when used in a function, is the object that “owns” the function. The value of this, when used in an object, is the object itself. The this keyword in an object constructor does not have a value.

3. Explain === operator?
=== is called as strict equality operator which returns true when the two operands are having the same value without any type conversion.

4. What are disadvantage of using innerHTML in JavaScript?
Content will be  replaced everywhere
Cannot use like “appending to innerHTML”
When you use +=like “innerHTML = innerHTML + ‘html’” still the old content is replaced by html
The entire innerHTML content is re-parsed and build into elements, therefore its much slower
The innerHTML does not provide validation and therefore we can potentially insert valid and broken HTML in the document and break it

5. What is JavaScript Cookies?
Cookies are the small test files stored in a computer and it gets created when the user visits the websites to store information that they need. Example could be User Name details and shopping cart information from the previous visits. The data contained in a cookie is automatically transmitted between the web browser and the web server, so CGI scripts on the server can read and write cookie values that are stored on the client. JavaScript can also manipulate cookies using the cookie property of the Document object

6. Explain pop() method in JavaScript?
pop() method is similar as the shift() method but the difference is that the Shift method works at the start of the array.
pop() method take the last element off of the given array and returns it. The array on which is called is then altered.
The pop method removes the last element from an array and returns that value to the caller. pop is intentionally generic; this method can be called or applied to objects resembling arrays.

7. built-in method that sorts the elements of an array?
sort() method sorts the elements of an array. The sort method sorts the Array object in place; no new Array object is created during execution.

8. 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.

Comments are closed here.