Pages

15 [Latest] Javascript Interview Questions With Answers PDF


Hiried Javascript Interview Questions And Answers PDF

1. Explain what is Javascript? List some data types supported by Javascript?
Javascript
Javascript is an object-oriented computer programming language commonly used to create interactive effects within web browsers.It is first used by the Netscape browser, that provides access to the HTML document object model (DOM), provides access to the browser object model (BOM). Javascript syntax looks a lot like java, c or c++ syntax.
Below is the list of data types supported by Javascript:-
•    Undefined
•    Null
•    Boolean
•    String
•    Symbol
•    Number
•    Object

2. In Javascript are calculations with fractional numbers guaranteed to be precise?
NO, calculations with fractional numbers are not guaranteed to be precise in Javascript

3. List the comparison operators supported by Javascript?
Javascript supports below comparison operators
•    > Greater than
•    < Less than
•    <= Less than or equal to
•    >= Greater than or equal to
•    === Equal to
•    !== Not equal to

4. How do you declare variables in Javascript?
In Javascript variable are declared using the var keyword.A variable must begin with A letter, $ or _.
eg. var myVar=”Online Interview Questions”;
PS: All variables in Javascript are Case sensitive.
Basic Javascript Interview Questions with Answers
5. What will happen if an infinite while loop is run in Javascript?
The program will crash the browser.

6. List HTML DOM mouse events?
HTML DOM mouse events
•    onclick
•    ondblclick
•    mousemove
•    mousedown
•    mouseover
•    mouseout
•    mouseup

7. How to get the last index of a string in Javascript?
string.length-1 is used to get the last index of a string in Javascript
Example Usage:-
var myString="JavascriptQuestions";
console.log(myString.length-1);

8. How to get the primitive value of a string in Javascript?
In Javascript valueOf() method is used to get the primitive value of a string.
Example Usage:
var myVar= "Hi!"
console.log(myVar.valueOf())

9. What are the primitive data types in JavaScript?
A primitive is a basic data type that’s not built out of other data types. It can only represent one single value. All primitives are built-in data types by necessity, (the compiler has to know about them,) but not all built-in data types are primitives.
In JavaScript there are 5 primitive data types are available they are undefined, null, boolean, string and number are available.Everything else in Javascript is an object.

10. What does the instanceof operator do?
In Javascript instanceof operator checks whether the object is an instance of a class or not:
Example Usage
Square.prototype = new Square();
console.log(sq instanceof Square); // true

11. What is Javascript BOM?
BOM stands for “Browser Object Modal” that allows Javascript to ‘talk’ to the browser, no standards, modern browsers implement similar BOMS – window, screen, location, history, navigator, timing, cookies.

12. What are different types of Popup boxes available in Javascript?
In Javascript there are 3 types of Popup Boxes are available, they are
•    Alert
•    Confirm
•    Prompt

13. How can you create an array in Javascript?
There are 3 different ways to create an array in Javascript. They are
•    By array literal
usage:
 var myArray=[value1,value2...valueN];
•    By creating instance of Array
usage:
var myArray=new Array();
•    By using an Array constructor
usage:
var myArray=new Array('value1','value2',...,'valueN');

14. What is the ‘Strict’ mode in JavaScript and how can it be enabled?
Strict mode is a way to introduce better error-checking into your code. When you use strict mode, you cannot, for example, use implicitly declared variables, or assign a value to a read-only property, or add a property to an object that is not extensible.
You can enable strict mode by adding “use strict”; at the beginning of a file, a program, or a function. This kind of declaration is known as a directive prologue. The scope of a strict mode declaration depends on its context. If it is declared in a global context (outside the scope of a function), all the code in the program is in strict mode. If it is declared in a function, all the code in the function is in strict mode.

15. How to calculate Fibonacci numbers in JavaScript?
Calculating Fibonacci series in JavaScript
Fibonacci numbers are a sequence of numbers where each value is the sum of the previous two, starting with 0 and 1. The first few values are 0, 1, 1, 2, 3, 5, 8, 13 ,…,
function fib(n) {
    var a=0, b=1;
    for (var i=0; i < n; i++) {
        var temp = a+b;
        a = b;
        b = temp;
    }
    return a;
}

16. What is the difference between the substr() and substring() functions in JavaScript?
Difference between the substr() and substring() functions in JavaScript.
The substr() function has the form substr(startIndex,length). It returns the substring from startIndex and returns ‘length’ number of characters.
var s = "hello";
( s.substr(1,4) == "ello" ) // true
The substring() function has the form substring(startIndex,endIndex). It returns the substring from startIndex up to endIndex – 1.
var s = "hello";
( s.substring(1,4) == "ell" ) // true

Latest Javascript Interview Questions for freshers and Experienced pdf

No comments:

Post a Comment