JavaScript Interview Questions (Part2)
What is JavaScript?
JavaScript is a scripting or programming language designed primarily for adding interactivity to Web pages and creating Web applications. It is an interpreted programming language with object-oriented capabilities. Alongside HTML and CSS, JavaScript is one of the three core technologies of the World Wide Web. It is supported by most web browsers including Chrome, Firefox, Safari, internet Explorer, Edge, Opera, etc. Most mobile browsers for smart phones support JavaScript too.Which company developed JavaScript?
JavaScript was initially known by the name LiveScript. It was developed in mid nineties by a company called Netscape. The first JavaScript engine was created by Brendan Eich at Netscape, for the Netscape Navigator Web browser.
What data types are supported in Javascript?
According to the latest ECMAScript release, following are the data types supported in Javascript:
- Boolean
- Null
- Undefined
- Number
- String
- Symbol
- Object
What is the difference between JavaScript and Jscript?
Both JavaScript and jscript designed for to make web page More dynamic. JavaScript is a scripting language developed by Netscape Communications designed for developing client and server Internet applications. JScript is the Microsoft dialect of the ECMAScript scripting language specification. Microsoft reverse engineered Javascript and called it JScript to avoid trademark issues with Sun. JavaScript is the common term for a combination of the ECMAScript programming language plus some means for accessing a web browser's windows and the Document Object Model (DOM). It is used to develop client and server applications. It basically focuses how the page should react after triggering the JavaScript code.What are the primitive data types in JavaScript?
Javascript has five primitive data types:
- Number
- String
- Boolean
- Undefined
- Null
What are the Non-primitive data types in JavaScript?
- Object
- Date
- Array
What is the scope of variables in JavaScript?
The scope of a variable is controlled by the location of the variable declaration, and defines the part of the program where a particular variable is accessible. JavaScript has two scopes: global and local. Any variable declared outside of a function belongs to the global scope, and is therefore accessible from anywhere in your code. A variable that is declared inside a function definition is local. It is created and destroyed every time the function is executed, and it cannot be accessed by any code outside the function.Is JavaScript case sensitive? Give an example?
Yes, JavaScript is a case-sensitive language.
example"This" is not same as "this"
What are all the types of Pop up boxes available in JavaScript?
- Alert Box
- Confirm Box
- Prompt Box
How to use external JavaScript file?
External JavaScript files have the file extension .js. External scripts are practical when the same code is used in many different web pages. This is the way to include an external javascript file to you HTML markup.
Where "myscript.js" is your external JavaScript file.
Can javascript code be broken in different lines?
You can break javascript code in different lines by using a backslash "\" at the end.
Note that this backslash approach is not necessarily preferred, and possibly not universally supported.
Which keyword is used to print the text in the screen?
Using document.write(), you can print the text in the screen.
Which symbol is used for comments in Javascript?
There are two types of comments symbol used in JavaScript.
Single Line Comments // and Multi-line comments start with /* and end with */.
exampleCan I declare a variable as CONSTANT in JavaScript?
Yes. ECMAScript 2015 introduced the const keyword, but it thus far only enjoys a smattering of browser .
const CONSTANT_VAR = "some-value";
What is variable typing?
JavaScript is a very loosely typed language; the type of a variable is determined only when a value is assigned and can change as the variable appears in different contexts. This means that JavaScript variables can be reassigned to value of any type, so you don’t ever need to explicitly denote the type of variable or the return type of the function. JavaScript automatically adjusts the datatype while assigning or reassigning the variable.What is === operator?
The "===" operator is a binary logical operator to check whether the two values are same and are of same data type. It will return false even when their values are equal but they are not of same data type.
For ex: 555 and '555', according to the values are same but they are not of same data type, hence === will return false.
exampleThe above code return false
What are the basic groups of dataypes in JavaScript?
Primary Data Types
- String
- Number
- Boolean
Composite Data Types
- Object
- Array
Special Data Types
- Null
- Undefined
What is the difference between null and undefined in JavaScript?
In JavaScript, undefined means a variable has been declared but has not yet been assigned a value, such as:
null is an assignment value. It can be assigned to a variable as a representation of no value:
Between JavaScript and an ASP script, which is faster?
JavaScript is always faster. Java scripting is written for client-side , it does not need the web server's support for execution. It can be executed immediately or when some event occurs. ASP is a server side language so it does needs the assistance of the web server which is a time consuming process. Thus it will take time to send the request and get the response back from the server.
How to disable an HTML object ?
A disabled element is unusable and un-clickable. Disabled elements are usually rendered in grey by default in browsers to enable
How do you access an element in an HTML document with JavaScript?
If you want to access any element in an HTML page, you always start with accessing the document object.
Finds the element with id="foo":
The getElementById() method returns the element that has the ID attribute with the specified value.
What is the use of window object?
The window object in JavaScript represent the current window open in the browser. It contains information related to the current browser window. All global JavaScript objects, functions, and variables automatically become members of the window object.What does the "Access is Denied" IE error mean?
The reason is that Windows blocks one window or frame accessing another window or frame that is in a different domain.
How to detect browser name using JavaScript?
How to get height and width of different browser in Javascript?
What is screen object in JavaScript?
The window object also has a screen object with properties describing the physical display. It can be used to display screen width, height, colorDepth, pixelDepth etc.
How do you submit a form using JavaScript?
JavaScript provides the form object that contains the submit() method. You can perform javascript form submission by form attributes like id, name, class, tag name as well.
What are the decodeURI() and encodeURI()?
The encodeURI() function is used to encode a URI. It assumes that the input is a complete URI that might have some characters which need encoding in it. If you pass the result to decodeURI , the original string is returned.Difference between window.onload and onDocumentReady?
The onDocumentReady allows you to execute code when only the DOM tree has been built, without waiting for images to load, while window.onload will wait until all assets have finished downloading, such as images and scripts.What are JavaScript Cookies?
JavaScript cookies are the small test files stored in your system and it gets created when the user visits the websites to store information that they need. For ex. User Name details and shopping cart information from the previous visits.
Can you access Cookie using javascript?
Cookies are data, stored in small text files, on your computer. JavaScript can also manipulate cookies using the cookie property of the Document object. JavaScript can read, create, modify, and delete the cookie or cookies that apply to the current web page.Whether JavaScript has concept level scope?
No. JavaScript does not have concept level scope. The variable declared inside the function has scope inside the function.
How to get the primitive value of a string in Javascript?
The valueOf() method is used to get the primitive value of a string Object. This value is equivalent to ring.prototype.toString().
How can you convert the string of any base to integer in JavaScript?
The JavaScript parseInt() Function, which convert the string of any base into integer in javascript.
exampleBase(optional): An integer between 2 and 36 that represents the radix (the base in mathematical numeral systems) of the above mentioned string.
example- JavaScript Interview Questions (Part3)
- Is JavaScript a true OOP language?
- Advantages and Disadvantages of JavaScript
- Difference Between JavaScript and ECMAScript?
- What is noscript tag?
- Escaping Special Characters in JavaScript
- What is undefined x 1 in JavaScript?
- JavaScript : Logical Operators
- Difference between '=', '==' and '===' operators?
- How to reload a page using JavaScript?
- How to write html code dynamically using JavaScript?
- How to add html elements dynamically with JavaScript?
- How to load another html page from javascript?
- What Is The Disadvantages Using InnerHTML In JavaScript?
- What is Browser Object Model
- How to detect the OS on the client machine in JavaScript?
- Difference between window, document, and screen in Javascript?
- Difference between the substr() and substring() in JavaScript?
- How to replace all occurrences of a string in JavaScript?
- How to test a string as a literal and as an object ?
- What is Associative Array? How do we use it?
- What is an anonymous function in JavaScript?
- What is the use of 'bind' method in JavaScript?
- Pure functions Vs. Impure functions in javascript
- Is Javascript a Functional Programming Language?
- What's the Difference Between Class and Prototypal Inheritance?
- Javascript, Pass by Value or Pass by Reference?
- How to prevent modification of an object in Javascript?
- What is 'this' keyword in JavaScript?
- How Does Function Hoisting Work in JavaScript?
- What do mean by NULL in Javascript?
- What does the delete operator do in JavaScript?
- What is the Infinity property used for in Javascript?
- Event bubbling and Event Capturing in JavScript?
- What is "strict mode" and how is it used in JavaScript?
- What is the difference between .call() and .apply()?
- Entire content of a JavaScript source file in a function block?
- What is an immediately-invoked function expression?
- What is escape & unescape String functions in JavaScript?
- What is the instanceof operator in JavaScript?
- What Are RESTful (REpresentational State Transfer)Web Services?
- What is Unobtrusive JavaScript & Why it's Important?
- What Does JavaScript Void(0) Mean?
- What are JavaScript Cookies?
- Difference between Client side JavaScript and Server side JavaScript
- TypeError: document.getelementbyid(...) is null
- Uncaught TypeError: Cannot read property of undefined In JavaScript
- What's the difference between Null and Undefined?