
JavaScript provides different data types to hold different types of values.
There are mainly category of two types of data types available in JavaScript.
- Primitive data type
- Non-primitive (reference) data type
- Boolean
- Number
- String
- Null
- Undefined
- Symbol
- Object
- Array
- Alert Box
- Confirm Box
- Prompt Box
You may also like - Advanced JavaScript Interview Questions
DOM stands for Document Object Model, DOM: This consists of objects that have to deal with the currently loaded page, which is also called the document.
#Example: document
BOM stands for Browser Object Model. Unlike DOM, there is no standard defined for BOM, hence different browsers implement it in different ways. Typically, the collection of browser objects is collectively known as the Browser Object Model.
BOM is superset of DOM.
#Example: navigator, screen, location, frames,history, XMLHttpRequest etc
Window is root global object in JavaScript.
All global JavaScript objects, functions, and variables automatically become members of the window object.
Even the document object (of the HTML DOM) is a property of the window object.
defer scripts are executed once the parser has finished it's job. defer scripts also gaurantees the order of execution in which they were added in page.
defer will download the file/script during HTML parsing, execute file/script only when the parser has finished it's job.
async scripts are executed as soon as the script is loaded. async scripts doesn't gaurantees the order of execution in which they were added in page.
async will download the file/script during HTML parsing, and halt the parser and execute the file/script and then again parser start it's job.
"use strict"; tells browser that JavaScript code should be executed in "strict mode".
Strict mode is a new feature of ECMAScript 5 or ES5.
- It makes code debugging more easier.
- It eliminates javascript silent errors and throw errors.
- use strict enforces strict parsing and error handling.
- Strict mode makes it easier to write "secure" JavaScript.
- It is a good practice, developer should use - "use strict" mode.
- It is supported by all modern browsers.
You may also like - Node Js Interview Questions And Answers
There are two types of comments in JavaScript.
- Single Line Comment: It is represented by double forward slash.
- Multi Line Comment: It is represented by forward slash with asterisk symbol.
The == operator checks values only whereas === checks values and data type.
The $(document).ready() event occurs as early as the HTML document start loading, while the window.onload event occurs later when all content (e.g. images etc.) has been loaded.
try lets you test a block of code for errors.
catch lets you handle the error.
throw lets you create custom errors.
finally lets you execute code, after try and catch, regardless of the result.
HTML DOM mouse events
- onclick
- ondblclick
- mousemove
- mousedown
- mouseover
- mouseout
- mouseup
You may also like - Javascript ES6 Interview Questions
string.length-1 is used to get the last index of a string in Javascript
In Javascript valueOf() method is used to get the primitive value of a string.
There are 3 different ways to create an array in Javascript.
-
By Array Literal
Example: var myArray = [value1,value2...valueN];
-
By creating Instance of Array
Example: var myArray = new Array();
-
By using an Array constructor
Example: var myArray = new Array('value1','value2',...,'valueN');
You can use unshift and push function
You can also use ES6 spread operator
You can use splice function add an element into an array at any specific postion.
The substr() function has the form substr(startIndex,length). It returns the substring from startIndex and returns length number of characters.
The substring() function has the form substring(startIndex,endIndex). It returns the substring from startIndex up to endIndex – 1.
Frames allow you to divide the page into several rectangular areas and to display a separate document in each rectangle. Each of those rectangles are called a "frame".
In JavaScript, there are the following three types of errors:
- Syntax Error
- Runtime Error
- Logic Error
You may also like - React Js Interview Questions and Answers
Page redirection means moving to another location or the page, using JavaScript at the client side.
Using window.location
Using window.location.href
Using window.location.assign
Using window.location.replace
using window.open
Ans: - 3030
Reason: 10 and 20 are integer, So they will be added numerically. And since 30 is a string, So it will be concat and final output will be 3030.
Ans: - 302010
Reason: Since 30 is a string which is at the starting of expression, So it will be concat with all later values so final output will be 302010.
true, becasue javascript is a case-sensitive, so typeof NULL is undefined
false, becasue typeof null is object