JavaScript Flashcards

1
Q

What is JavaScript?

A

JavaScript is a client-side scripting language that can be inserted into HTML to make dynamic web pages

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What makes JavaScript dynamic?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the advantages of JavaScript?

A

Less Server Interaction
Immediate feedback
Increased activity
Richer interfaces

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

JavaScript Less Server Interaction

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

JavaScript Immediate Acitivity

A

Immediate feedback to the visitors − They don’t have to wait for a page reload to see if they have forgotten to enter something.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

JavaScript Increased activity

A

Increased interactivity − You can create interfaces that react when the user hovers over them with a mouse or activates them via the keyboard.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

JavaScript Richer Interfaces

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the limitations of JavaScript

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the JavaScript data types?

A
Boolean
Function
Number
Null (is an Object)
Object
String
Undefined (Type)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What makes JavaScript an OOP language?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is NaN

A

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).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the isNan function?

A

The isNan function returns a boolean. It returns true when the parameters that get passed through is NOT a number, otherwise it returns false.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is negative infinity?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are undeclared and undefined variables?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How can you add new elements dynamically?

A

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); 
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are global variables? How are these variable declared and what are the problems associated with using them?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Explain the working of timers in JavaScript? Also discuss the drawbacks of using the timer, if any?

A

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().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is === operator?

A

JavaScript has two comparison operator. The === is the strict comparison operator which compares both the datatype and the internal references

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is the == operator?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Explain how can you submit a form using JavaScript?

A

To submit a form using JavaScript use document.getElementById(“myform”).submit();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is an undefined value in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What are some common JavaScript events?

A

onchange: When user change selected options
onclick:
onmouseover:
onmouseout:
onkeydown:
onload; When page change

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is jQuery?

A

jQuery is a JavaScript library, it is not a programming language but a well written JavaScript code.

It is used to 
simplify HTML document traversing, 
event handling, 
animating, 
and Ajax interactions.
24
Q

What are the methods used to provide effects?

A
Some of the effects methods are:
Show( )
Hide( )
Toggle( )
FadeIn( )
FadeOut( )
25
Q

In what scenarios jQuery can be used?

A

DOM manipulation − The jQuery made it easy to select DOM elements, traverse them and modifying their content by using cross-browser open source selector engine called Sizzle.

Event handling − The jQuery offers an elegant way to capture a wide variety of events, such as a user clicking on a link, without the need to clutter the HTML code itself with event handlers.

AJAX Support − The jQuery helps you a lot to develop a responsive and feature-rich site using AJAX technology.

Animations − The jQuery comes with plenty of built-in animation effects which you can use in your websites.

26
Q

What are the basic selectors in jQuery?

A

Following are the basic selectors in jQuery:
Element ID: It must be unique in a document, and is often used to retrieve the element using

getElementById.
CSS Name
Tag Name
DOM hierarchy

27
Q

Can we add more than one ‘document.ready’ function in a page?

A

Yes, we can add more than one document.ready function in a page. But, body.onload can be added once in a page.

28
Q

What are the four parameters used for jQuery.ajax method?

A
  • URL – Need to specify the URL to send the request
  • type – Specifies type of request(Get or Post)
  • data – Specifies data to be sent to server
  • Cache – Whether the browser should cache the requested page
29
Q

What is Ajax?

A

Asynchronous JavaScript + XML
That describes a “new” approach to using a number of existing technologies together, including:

HTML or XHTML, 
Cascading Style Sheets, 
JavaScript, 
The Document Object Model, 
XML, 
XSLT, and most importantly the 
XMLHttpRequest object.

When these technologies are combined in the Ajax model, web applications are able to make quick, incremental updates to the user interface without reloading the entire browser page. This makes the application faster and more responsive to user actions.

30
Q

What are the advantages of Ajax?

A

The two major features of AJAX allow you to do the following:

Make requests to the server without reloading the page
Receive and work with data from the server

31
Q

What are the disadvantages of Ajax?

A
  1. AJAX is dependent on Javascript. If there is some Javascript problem with the browser or in the OS, Ajax will not support
  2. Ajax can be problematic in Search engines as it uses Javascript for most of its parts.
  3. Source code written in AJAX is easily human readable. There will be some security issues in Ajax.
  4. Debugging is difficult
  5. Increases size of the requests
  6. Slow and unreliable network connection.
  7. Problem with browser back button when using AJAX enabled pages.
32
Q

How many types of triggers are present in update panel?

A

There are two types of triggers used in update panel:
•PostBackTrigger – This works as full postback and it cannot work asynchronously
•AsyncPostBackTrigger – Partial post back asynchronously

33
Q

What are all the controls of Ajax?

A
  • ScriptManager
  • ScriptManagerProxy
  • UpdatePanel
  • UpdateProgress
  • Timer
34
Q

What is update panel?

A

Update panel is a server control used to update the specified portion of a web page. Script Manager needs to be used whenever update panel is used. Using update panel, user cannot handle outside controls.

35
Q

What are all the technologies used by Ajax?

A
  • JavaScript
  • XMLHttpRequest
  • Document Object Model (DOM)
  • Extensible HTML (XHTML)
  • Cascading Style Sheets (CSS)
36
Q

What is JSON in Ajax?

A

The JSON object contains methods for parsing JavaScript Object Notation (JSON) and converting values to JSON. SON is a syntax for serializing objects, arrays, numbers, strings, booleans, and null. It is based upon JavaScript syntax but is distinct from it: some JavaScript is not JSON, and some JSON is not JavaScript. JSON is a safe and reliable data interchange format in JavaScript, which is easy to understand for both users and machines.

37
Q

What is AngularJS?

A

AngularJS is a structural framework for dynamic web apps. It lets you use HTML as your template language and lets you extend HTML’s syntax to express your application’s components clearly and succinctly. AngularJS’s data binding and dependency injection eliminate much of the code you would otherwise have to write. And it all happens within the browser, making it an ideal partner with any server technology.

38
Q

What is scope in AngularJS?

A

Scope refers to the application model, it acts like glue between application controller and the view. Scopes are arranged in hierarchical structure and impersonate the DOM ( Document Object Model) structure of the application. It can watch expressions and propagate events.

39
Q

What are directives? Mention some of the most commonly used directives in AngularJS application.

A
A directive is something that introduces new syntax, they are like markers on DOM element which attaches a special behavior to it. In any AngularJS application, directives are the most important components. Some of the commonly used directives are 
ng-model 
ng-app 
ng-bind 
ng-repeat 
ng-show
40
Q

What are the advantages of using AngularJS

A

No need to use observable functions; Angular analyses the page DOM and builds the bindings based on the Angular-specific element attributes. That requires less writing, the code is cleaner, easier to understand and less error prone.
Angular modifies the page DOM directly instead of adding inner HTML code. That is faster.
Data binding occurs not on each control or value change (no change listeners) but at particular points of the JavaScript code execution. That dramatically improves performance as a single bulk Model/View update replaces hundreds of cascading data change events.
Quite a number of different ways to do the same things, thus accommodating to particular development styles and tasks.

41
Q

What is injector?

A

An injector is a service locator. It is used to retrieve object instances as defined by provider, instantiate types, invoke methods and load modules. There is a single injector per Angular application, it helps to look up an object instance by its name.

42
Q

What is the difference between link and compile in Angular.js?

A
  • Compile function: It is used for template DOM Manipulation and collect all of the directives.
  • Link function: It is used for registering DOM listeners as well as instance DOM manipulation. It is executed once the template has been cloned.
43
Q

What are the styling form that ngModel adds to CSS classes ?

A
ngModel adds these CSS classes to allow styling of form as well as control
•ng- valid
•ng- invalid
•ng- pristine
•ng- dirty
44
Q

Explain what is DI (Dependency Injection ) and how an object or function can get a hold of its dependencies?

A

DI or Dependency Injection is a software design pattern that deals with how code gets hold of its dependencies. In order to retrieve elements of the application which is required to be configured when module gets loaded , the operation “config” uses dependency injection.

These are the ways that object uses to hold of its dependencies
•Typically using the new operator, dependency can be created
•By referring to a global variable, dependency can be looked up
•Dependency can be passed into where it is required

45
Q

What is the difference between AngularJS and backbone.js?

A

AngularJS combines the functionalities of most of the 3rd party libraries, it supports individual functionalities required to develop HTML5 Apps. While Backbone.js do their jobs individually.

46
Q

What is JavaScript Truthy?

A

In JavaScript, a truthy value is a value that is considered true when evaluated in a Boolean context. All values are truthy unless they are defined as falsy (i.e., except for false, 0, “”, null, undefined, and NaN).

if (true)
if ({})
if ([])
if (42)
if ("foo")
if (new Date())
if (-42)
if (3.14)
if (-3.14)
if (Infinity)
if (-Infinity)
47
Q

What is JavaScript Falsy?

A

A falsy value is a value that translates to false when evaluated in a Boolean context.

if (false)
if (null)
if (undefined)
if (0)
if (NaN)
if ('')
if ("")
if (document.all)
48
Q

What is the Promise object?

A

The Promise object is used for asynchronous computations. A Promise represents a value which may be available now, or in the future, or never.

49
Q

XMLHTTPRequest ready states

A

Value State Description
0 UNSENT
Client has been created. open() not called yet.
1 OPENED
open() has been called.
2 HEADERS_RECEIVED
send() has been called, and headers and status are available.
3 LOADING
Downloading; responseText holds partial data.
4 DONE
The operation is complete.

50
Q

What is event bubbling?

A

When an event happens on an element, it first runs the handlers on it, then on its parent, then all the way up on other ancestors.

51
Q

How do you stop bubbling?

A

A bubbling event goes from the target element straight up. Normally it goes upwards till html tag, and then to document object, and some events even reach window, calling all handlers on the path.

But any handler may decide that the event has been fully processed and stop the bubbling.

The method for it is event.stopPropagation().

52
Q

What is event capturing?

A
  1. Capturing phase – the event goes down to the element.
  2. Target phase – the event reached the target element.
  3. Bubbling phase – the event bubbles up from the element.
53
Q

What is DOMContentLoaded?

A

domContentLoaded is the point when both the DOM is ready and there are no stylesheets that are blocking JavaScript execution
This event typically marks when both the DOM and CSSOM are ready.
This means that the render tree can now be built.
If there is no parser blocking JavaScript then DOMContentLoaded will fire immediately after domInteractive.

54
Q

What is Jackson?

A

Jackson (JavaScript Object Notation)

Jackson is a multi-purpose Java library for processing JavaScript Object Notation (JSON) data format. Jackson is an open source JSON parser and data binder. Jackson provides the capability to convert Java objects to JavaScript objects and to convert JavaScript objects to Java objects. Jackson supports data binding, tree-based data models, and incremental streaming. Jackson provides capability to maintain sub-type information during java object serialization and allows type information to be embedded into JSON as a property, which allows specific object types to be created during de-serializing. Jackson also provides the ability to annotate third party classes using mix-in abstract classes.

55
Q

What is JSON?

A

JSON, or JavaScript Object Notation, is a minimal, readable format for structuring data. It is used primarily to transmit data between a server and web application, as an alternative to XML