Basic JavaScript interview questions
Top Javascript interview questions for Freshers and experienced
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
NO, calculations with fractional numbers are not guaranteed to be precise in 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
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.
Also, read Advanced JavaScript Interview Questions
The program will crash the browser.
HTML DOM mouse events
- onclick
- ondblclick
- mousemove
- mousedown
- mouseover
- mouseout
- mouseup
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);
In Javascript valueOf() method is used to get the primitive value of a string.
Example Usage:
var myVar= "Hi!" console.log(myVar.valueOf())
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.
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
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.
In Javascript there are 3 types of Popup Boxes are available, they are
- Alert
- Confirm
- Prompt
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');
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.
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; }
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
Basic JavaScript interview questions
Reviewed by Pakainfo
on
July 21, 2018
Rating:
No comments: