JavaScript Flashcards
What is JavaScript?
JavaScript is a client-side scripting language that can be inserted into HTML to make dynamic web pages
What makes JavaScript dynamic?
JavaScript can include programs that interact with the user, control the browser, and dynamically create HTML content.
JavaScript can be used to trap user-initiated events such as button clicks, link navigation, and other actions that the user initiates explicitly or implicitly.
What are the advantages of JavaScript?
Less Server Interaction
Immediate feedback
Increased activity
Richer interfaces
JavaScript Less Server Interaction
Less server interaction − You can validate user input before sending the page off to the server. This saves server traffic, which means less load on your server.
JavaScript Immediate Acitivity
Immediate feedback to the visitors − They don’t have to wait for a page reload to see if they have forgotten to enter something.
JavaScript Increased activity
Increased interactivity − You can create interfaces that react when the user hovers over them with a mouse or activates them via the keyboard.
JavaScript Richer Interfaces
Richer interfaces − You can use JavaScript to include such items as drag-and-drop components and sliders to give a Rich Interface to your site visitors.
What are the limitations of JavaScript
We cannot treat JavaScript as a full-fledged programming language. It lacks the following important features −
Client-side JavaScript does not allow the reading or writing of files. This has been kept for security reason.
JavaScript cannot be used for networking applications because there is no such support available.
JavaScript doesn’t have any multithreading or multiprocessor capabilities.
Once again, JavaScript is a lightweight, interpreted programming language that allows you to build interactivity into otherwise static HTML pages.
What are the JavaScript data types?
Boolean Function Number Null (is an Object) Object String Undefined (Type)
What makes JavaScript an OOP language?
JavaScript provides
Encapsulation − the capability to store related information, whether data or methods, together in an object.
Aggregation − the capability to store one object inside another object.
Inheritance − the capability of a class to rely upon another class (or number of classes) for some of its properties and methods.
Polymorphism − the capability to write one function or method that works in a variety of different ways.
What is NaN
Not a Number, it is the result of trying to parse a non number or performing a math function that results in a non number, Math.sqrt(-1).
What is the isNan function?
The isNan function returns a boolean. It returns true when the parameters that get passed through is NOT a number, otherwise it returns false.
What is negative infinity?
A negative infinity is the negative value of an infinity property. We can get a negative infinity by multiplying a negative number by 0. Multiplying a negative infinity get us a NaN
What are undeclared and undefined variables?
Undeclared variable simply means calling for a variable that does not exist
Undefined variable simply means that you haven’t specify that the particular datatype that variable is
How can you add new elements dynamically?
document.body.onload = addElement;
function addElement () { // create a new div element // and give it some content var newDiv = document.createElement("div"); var newContent = document.createTextNode("Hi there and greetings!"); newDiv.appendChild(newContent); //add the text node to the newly created div.
// add the newly created element and its content into the DOM var currentDiv = document.getElementById("div1"); document.body.insertBefore(newDiv, currentDiv); }
What are global variables? How are these variable declared and what are the problems associated with using them?
Global variables are variables that can be accessed within any scope of the source code. They can be declared by omitting the keyword var when defining the variable. The problems with using a global variable is that since it isn’t scope specific, it makes it hard to maintain and the scope becomes less clear, which makes it much harder to read or modify.
Explain the working of timers in JavaScript? Also discuss the drawbacks of using the timer, if any?
JavaScript code generally run synchronously. When you use a JavaScript timer, which runs on a single thread, you make other events queue up since the goal of a timer is to delay specific functions.
We can use the JS timer by using the property accessor (.) to call for many different timers.
The setTimeout() function is commonly used if you wish to have your function called once after the specified delay.
The setInterval() function is commonly used to set a delay for functions that are executed again and again, such as animations.
clearImmediate()
Cancels the immediate actions, just like clearTimeout() for setTimeout().
What is === operator?
JavaScript has two comparison operator. The === is the strict comparison operator which compares both the datatype and the internal references
What is the == operator?
The == is the equality operator. It converts both operand type if they are not the same to be the same type before comparing their values.
Explain how can you submit a form using JavaScript?
To submit a form using JavaScript use document.getElementById(“myform”).submit();
What is an undefined value in JavaScript?
The Undefined property is a primitive datatype of JS. When a value is considered undefined, it simply means that the value has not been set to a type.
What are some common JavaScript events?
onchange: When user change selected options
onclick:
onmouseover:
onmouseout:
onkeydown:
onload; When page change