JavaScript Practice Interview Questions

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

How to detect the operating system on the client machine?

navigator.appVersion

How do you assign object properties?

obj["age"] = 17 or obj.age = 17

1.) What does "1"+2+4 evaluate to? 2.) How about 2+5+"8"?

124 and 78

What boolean operators does JavaScript support?

&&, || and !

What is the difference between undefined value and null value?

undefined means a variable has been declared but has not yet been assigned a value. On the other hand, null is an assignment value. It can be assigned to a variable as a representation of no value. Also, undefined and null are two distinct types: undefined is a type itself (undefined) while null is an object. Unassigned variables are initialized by JavaScript with a default value of undefined. JavaScript never sets a value to null. That must be done programmatically.

How do you create a new object in JavaScript?

var obj = new Object(); or var obj = {};

How to create arrays in JavaScript?

Regular declaration: var scripts = new Array(); scripts[0] = "PHP"; scripts[1] = "ASP"; scripts[2] = "JavaScript"; scripts[3] = "HTML"; Condensed declaration: var no_array = new Array(21, 22, 23, 24, 25); Literal declaration: var myCars=["Saab","Volvo","BMW"];

What are the problems with using globals?

Most JavaScript developers avoid globals. One reason why is they're averse to naming conflicts between local and globals, Also, code that depends on globals can be difficult to maintain and test.

What are the various datatypes in javascript?

Number String Boolean Function Object Null Undefined

What is JS "closure"?

A basic overview of javascript closures is that it is a stack-frame which is not de-allocated when the function returns. In JavaScript, a closure is a function to which the variables of the surrounding context are bound by reference. i.e.: "a nested function"

What's relationship between JavaScript and ECMAScript?

ECMAScript is yet another name for JavaScript (other names include LiveScript). The current JavaScript that you see supported in browsers is ECMAScript revision 3.

What is event bubbling?

Event bubbling describes the behavior of events in child and parent nodes in the Document Object Model (DOM); that is, all child node events are automatically passed to its parent nodes. The benefit of this method is speed, because the code only needs to traverse the DOM tree once. This is useful when you want to place more than one event listener on a DOM element since you can put just one listener on all of the elements, thus code simplicity and reduction. One application of this is the creation of one event listener on a page's body element to respond to any click event that occurs within the page's body.

What is negative infinity?

It's a number in JavaScript, derived by dividing negative number by zero.

How is JavaScript different from Java?

Java is a full-fledged programming language tailored for network computing; it includes hundreds of its own objects, including objects for creating user interfaces that appear in Java applets (in Web browsers) or standalone Java applications. In contrast, JavaScript relies on whatever environment it's operating in for the user interface, such as a Web document's form elements.

What is JavaScript?

JavaScript is a platform-independent,event-driven, interpreted client-side scripting language developed by Netscape Communications Corp. and Sun Microsystems.

Differentiate between "var a=2" and "a =2"

The major difference between the two is that one variable is local and the other is global. "var" basically defines the scope of the variable. When we add var to a variable value assignment, javascript ensures that the variable is confined to whichever function it is assigned to and does not collide with the same name variable within another function. When we don't use var, then it is declared as a global function and chances of collision can happen. So it's always advisable to use "var" before variable value assignment. If needed use an anonymous function for closure.

Difference between window.onload and onDocumentReady?

The onload event does not fire until every last piece of the page is loaded, this includes css and images, which means there's a huge delay before any code is executed. The onDocumentReady event fires when the DOM is loaded and is able to be manipulated.

What is strict mode in JavaScript?

The strict mode ensures that if functions are not properly thought it, those are disabled. It also kept a check on potentially unsafe actions and throw errors when it happens.

How JavaScript timers work? What is a drawback of JavaScript timers?

Timers allow you to execute code at a set time or repeatedly using an interval. This is accomplished with the setTimeout, setInterval, and clearInterval functions. The setTimeout(function, delay) function initiates a timer that calls a specific function after the delay; it returns an id value that can be used to access it later. The setInterval(function, delay) function is similar to the setTimeout function except that it executes repeatedly on the delay and only stops when cancelled. The clearInterval(id) function is used to stop a timer. Timers can be tricky to use since they operate within a single thread, thus events queue up waiting to execute.

How do you convert numbers between different bases in JavaScript?

Use the parseInt() function, that takes a string as the first parameter, and the base as a second parameter. So to convert hexadecimal 3F to decimal, use parseInt ("3F", 16);

How is form submission possible via javascript?

We can achieve the desired form submission by using the function document.forms[0].submit(). It must be noted that the 0 in the piece of code given above refers to the form index. Say we have multiple forms on a particular page. To make all the form procession unique, we give each form index numbers. The first form will have the index number as 0. The second form will have an incremented number, 1. The third will have 2 and so on.

What is the difference between "==" and "==="?

While "==" checks only for equality, "===" checks for equality as well as the type.

Is it possible to check if a variable is an object?

Yes, it is possible to do so. The following piece of code will help achieve the same. if(abc && typeof abc === "object") { console.log('abc is an object and does not return null value'); }

What's a way to append a value to an array?

arr[arr.length] = value;

How do you change the style/class on any element?

document.getElementById("myText").style.fontSize = "20″; -or- document.getElementById("myText").className = "anyclass";

How do you get the CheckBox status whether it is checked or not?

document.getElementById('checkbox1').checked if it will be checked you will get true else false.

How do you get the value from dropdown (select) control?

document.getElementById('dropdown1').value

How do you get the value from a textbox?

document.getElementById('txtbox1').value

What are the loop structures in JavaScript?

for while do-while loop

How to get value from RadioButtonList control?

function GetRadioButtonValue(name) { var radio = document.getElementsByName(name); for (var ii = 0; ii < radio.length; ii++) { if (radio[ii].checked) alert(radio[ii].value); } }

Write a one-line JS function that concatenates all strings passed in.

function concatenate() { return String.prototype.concat.apply('', arguments); }

Can you explain what isNaN function does?

isNaN function will check an argument and return TRUE (1) if the argument does not seem to be a number.

What is JQuery?

jQuery is a quick as well as concise JavaScript Library that simplifies HTML document traversing, animating, event handling, & Ajax interactions for the purpose of quick web development needs.


Set pelajaran terkait

History of Rock MUS 28 Chapter 2

View Set

Chapter 15 HARVESTING THE ENTREPRENEURIAL VENTURE

View Set

Accounting - Debits & Credits PRACTICE

View Set

Chapter 11 (Within Subjects Experimental Design)

View Set