Net-informations.com
SiteMap  | About    

JavaScript Interview Questions FAQ - 1

Please click on the questions to see the answers

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.

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.

According to the latest ECMAScript release, following are the data types supported in Javascript:

  1. Boolean
  2. Null
  3. Undefined
  4. Number
  5. String
  6. Symbol
  7. Object

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.

Javascript has five primitive data types:

  1. Number
  2. String
  3. Boolean
  4. Undefined
  5. Null

  1. Object
  2. Date
  3. Array

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.

Yes, JavaScript is a case-sensitive language.

example

"This" is not same as "this"

  1. Alert Box
  2. Confirm Box
  3. Prompt Box

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.

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.

Using document.write(), you can print the text in the screen.

There are two types of comments symbol used in JavaScript. Single Line Comments // and Multi-line comments start with /* and end with */.

example

Yes. ECMAScript 2015 introduced the const keyword, but it thus far only enjoys a smattering of browser .

const CONSTANT_VAR = "some-value";

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.

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.

example

The above code return false

Primary Data Types

  1. String
  2. Number
  3. Boolean
Composite Data Types
  1. Object
  2. Array
Special Data Types
  1. Null
  2. Undefined

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:

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.

A disabled element is unusable and un-clickable. Disabled elements are usually rendered in grey by default in browsers

to enable

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.

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.

The reason is that Windows blocks one window or frame accessing another window or frame that is in a different domain.

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.

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.

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.

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.

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.

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.

No. JavaScript does not have concept level scope. The variable declared inside the function has scope inside the function.

The valueOf() method is used to get the primitive value of a string Object. This value is equivalent to String.prototype.toString().

The JavaScript parseInt() Function, which convert the string of any base into integer in javascript.

example

Base(optional): An integer between 2 and 36 that represents the radix (the base in mathematical numeral systems) of the above mentioned string.

example









net-informations.com (C) 2018    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.