You are on page 1of 7

Javascript Notite:

1.Why is it called a Ternary expression, what does the word "Ternary" indicate?
test ? expression1 : expression2

2.Why is extending built in JavaScript objects not a good idea?


Because extending objects that are already used in the code and used by someone else will cause bugs

3.Js Prorotypes
All JavaScript objects inherit the properties and methods from their prototype.
Objects created using an object literal, or with new Object(), inherit from a prototype called
Object.prototype.

4. What is function.prototype.bind
The bind() method creates a new function that, when called, has its this keyword set to the provided
value, with a given sequence of arguments preceding any provided when the new function is called.
EX: this.x = 9;
var module = {
x: 81,
getX: function() { return this.x; }
};
module.getX(); // 81
var getX = module.getX;
getX(); // 9, because in this case, "this" refers to the global object
// Create a new function with 'this' bound to module
var boundGetX = getX.bind(module);
boundGetX(); // 81
Internal use for this:
Function.prototype.bind = function (scope) {
var fn = this;
return function () {

return fn.apply(scope);
};
}

5.Explain event delegation


Event delegation allows you to avoid adding event listeners to specific nodes; instead, the event listener
is added to one parent. That event listener analyzes bubbled events to find a match on child elements
http://javascript.info/tutorial/bubbling-and-capturing

6. What is a closure
That is a closure. A function doesn't have to return in order to be called a closure. Simply accessing
variables outside of your immediate lexical scope creates a closure.

7. Hoisting
http://www.sitepoint.com/back-to-basics-javascript-hoisting/

8.Can you describe the difference between progressive enhancement and


graceful degradation?
So, graceful degradation is the practice of building your web functionality so that it provides a certain
level of user experience in more modern browsers, but it will also degrade gracefully to a lower level of
user in experience in older browsers. This lower level is not as nice to use for your site visitors, but it does
still provide them with the basic functionality that they came to your site to use; things do not break for
them.
Progressive enhancement is similar, but it does things the other way round. You start by establishing a
basic level of user experience that all browsers will be able to provide when rendering your web site, but
you also build in more advanced functionality that will automatically be available to browsers that can use
it.
In other words, graceful degradation starts from the status quo of complexity and tries to fix for the lesser
experience whereas progressive enhancement starts from a very basic, working example and allows for
constant extension for future environments. Degrading gracefully means looking back whereas enhancing
progressively means looking forward whilst keeping your feet on firm ground.

9.What's the difference between feature detection, feature inference, and using
the UA string?

Feature detection checks a feature for existence, e.g.:


if (window.XMLHttpRequest) { new XMLHttpRequest(); }
Feature inference checks for a feature just like feature detection, but uses another function because
itassumes it will also exist, e.g.:
if (document.getElementsByTagName) { element = document.getElementById(id); }
Checking the UA string is an old practice and should not be used anymore. You keep changing the UA
checks and never benefit from newly implemented features, e.g.:
if (navigator.userAgent.indexOf("MSIE 7") > -1){ //do something }

10. What are JSONP requests: CORS


JSONP stands for JSON with Padding and it is a workaround for loading data from different domains. It
loads the script into the head of the DOM and thus you can access the information as if it were loaded on
your own domain, thus by-passing the cross domain issue.
JSON and JSONP behave differently on both the client and the server. JSONP requests are not
dispatched using the XMLHTTPRequest (and the associated browser methods), instead a <script>tag is
created, whose source is set to the target URL. This script tag is then added to the DOM (normally the
<head>).
JSONP:
foo({ "bar": "baz" });

This is why you see JSONP requests containing the "callback" parameter; so the server knows the name
of the function to wrap the response around.
This function must exist in the global scope at the time the <script> tag is evaluated by the browser (once
the request has completed).

11. Javascript Promises


http://www.sitepoint.com/overview-javascript-promises/
http://www.html5rocks.com/en/tutorials/es6/promises/
At its core, a Promise represents the result of a task, which may or may not have completed. The only
interface requirement of a Promise is having a function called then, which can be given callbacks to be
called when the promise is fulfilled or has failed

Well, the real power of promises comes from chaining multiple of them together. Calling
promise.then(func) returns a new promise, which is not fulfilled until func has completed. But theres one
really special thing about the way func is used. If a callback supplied to then returns a new promise, then
the promise returned by then will not be fulfilled until the promise returned by the callback is fulfilled
http://www.mattgreer.org/articles/promises-in-wicked-detail/

12. Main advantages and disatvantages of using use strict

Makes debugging easier.


Prevents accidental globals.
Disallows duplicate property names or parameter values.
Makes eval() safer.
Throws error on invalid usage of delete.

13.What is JavaScript's this keyword?


JavaScript's this keyword normally refers to the object that owns the method, but it depends on how a
function is called. Basically, it points to the currently in scope object that owns where you are in the code.
When working within a Web page, this usually refers to the Window object. If you are in an object created
with the new keyword, the this keyword refers to the object being created. When working with event
handlers, JavaScript's this keyword will point to the object that generated the event.

14. Inheritance and associacion of Javascript with Java


https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Details_of_the_Object_Model

function Employee() {
this.name = "";
this.dept = "general";
}
function Manager() {
Employee.call(this);
this.reports = [];
}
Manager.prototype = Object.create(Employee.prototype);

15.How do 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.Timers can be tricky to use since they operate
within a single thread, thus events queue up waiting to execute.

16. Write about the errors shown in JavaScript?


JavaScript gives a message if it encounters an error. The recognized errors are

Load-time errors: The errors shown at the time of the page loading are counted

under Load-time errors. These errors are encountered by the use of improper syntax, and
thus are detected while the page is getting loaded.

Run-time errors: This is the error that comes up while the program is running. It is
caused by illegal operations, for example, division of a number by zero, or trying to access a
non-existent area of the memory.

Logic errors: It is caused by the use of syntactically correct code, which does not
fulfill the required task. For example, an infinite loop.

17. Design Patterns:


A. Behavioural Patterns.
1. COMMAND -> Encapsulate a request as an object, thereby letting you parameterize clients with
different requests
2. MEDIATOR -> Define an object that encapsulates how a set of objects interact. Object coordinates
interaction between multiple objects.
3. OBSERVER Publisher/Subscriber -> Define a one-to-many dependency between objects where a state
change in one object results in all its dependents being notified
B. Structural Patterns.
a. FACADE -> Provide a unified interface to a set of interfaces in a subsystem. O fatada care
redirectioneaza anumite call-uri spre alte subclase sau ce o fi.
b. DECORATOR -> Attach additional responsibilities to an object. Single object and progressible
decorator objects to provide additional capabilities.
c. MODULE -> Creating a self contained module and variables are shielded from global scope. Existence
are limited within module closure.
EX: (function(){})()
Advantages: Supports private data, unable to touch private parts outside the word, provide only an API
Disadvantages: Private not flexible. Really hard to change visibility.
C. Creational patterns.
a. CONSTRUCTOR-> Define an interface for creating a single object. Ex: function Andrei with
this.module, this.name, this.lastname, this.email.Declare a var divic = new Andrei(asd, Andrei, Kun,
andrei.kun@gnmail.com)

b. SINGLETON -> Ensure a class has only one instance. Looks just like a module, encapsulated code
within a (function(){})() but has a way of checking if an instance already exists and returns existing
instance.
c. PROTOTYPE -> Specify the kinds of objects to create using a prototypical instance, and create new
objects by copying this prototype.
Create objects which acts as prototype to other objects.
ex: Object.create(vehicle, { data});
e. FACTORY - Provide a generic interface of creating objects and passing different data to them.

Usefull links:
1.http://www.htmlgoodies.com/beyond/javascript/object.create-the-newway-to-create-objects-in-javascript.html
2.https://developer.mozilla.org/enUS/docs/Web/JavaScript/Reference/Global_Objects/Object/create
3.https://developer.mozilla.org/enUS/docs/Web/JavaScript/Guide/Details_of_the_Object_Model
18. Difference between HTML and XHTML
What Is XHTML?

XHTML stands for EXtensible HyperText Markup Language


XHTML is almost identical to HTML
XHTML is stricter than HTML
XHTML is HTML defined as an XML application
XHTML is supported by all major browsers

XML is a markup language where documents must be marked up correctly (be "well-formed").

19. Difference between script async and deffer


http://www.growingwiththeweb.com/2014/02/async-vs-defer-attributes.html
20. What is a data- attribute ?
We can now use this stored data in our sites JavaScript to create a richer, more engaging user
experience. Imagine that when a user clicks on a vegetable a new layer opens up in the browser
displaying the additional seed spacing and sowing instructions. Thanks to the data-attributes weve added

to our <li> elements, we can now display this information instantly without having to worry about making
any Ajax calls and without having to make any server-side database queries.
Prefixing the custom attributes with data- ensures that they will be completely ignored by the user agent.
As far as the browser and indeed the websites end user are concerned, this data does not exist.
As custom data attributes are valid HTML5, they can be used in any browser that supports HTML5
doctypes

You might also like