Interview Prep

¡Supera tus tareas y exámenes ahora con Quizwiz!

How many looping structures can you find in javascript?

for, while, do-while

Discuss possible ways to write a function isInteger(x) that determines if x is an integer.

function isInteger(x){ if(x != Math.floor(x)){ console.log(x + ' is not an integer'); }else{ console.log(x + ' is an integer'); } } In ECMAScript 6, you can simply do a use the class method Number.isInteger()

What is a bubble sort?

A sorting algorithm that slowly "bubbles" its way to to the top of the list whether it be a minimum or maximum value.

What boolean operators exist in JavaScript?

&&, || and !

What are the principles of OOP? Describe each with an example.

abstraction, encapsulation, inheritance, and polymorphism. --> Abstraction: Abstraction is the concept of describing something in simpler terms, i.e abstracting away the details, in order to focus on what is important (This is also seen in abstract art, for example, where the artist focuses on the building blocks of images, such as colour or shapes). The same idea translates to OOP by using an inheritance hierarchy, where more abstract concepts are at the top and more concrete ideas, at the bottom, build upon their abstractions. At its most abstract level there is no implementation details at all and perhaps very few commonalities, which are added as the abstraction decreases. As an example, at the top might be an interface with a single method, then the next level, provides several abstract classes, which may or may not fill in some of the details about the top level, but branches by adding their own abstract methods, then for each of these abstract classes are concrete classes providing implementations of all the remaining methods. --> Encapsulation: Encapsulation is a strategy used as part of abstraction. Encapsulation refers to the state of objects - objects encapsulate their state and hide it from the outside; outside users of the class interact with it through its methods, but cannot access the classes state directly. So the class abstracts away the implementation details related to its state. --> Polymorphism: Polymorphism is a long word for a very simple concept. Polymorphism describes a pattern in object oriented programming in which classes have different functionality while sharing a common interface. The beauty of polymorphism is that the code working with the different classes does not need to know which class it is using since they're all used the same way. A real world analogy for polymorphism is a button. Everyone knows how to use a button: you simply apply pressure to it. What a button "does," however, depends on what it is connected to and the context in which it is used — but the result does not affect how it is used. If your boss tells you to press a button, you already have all the information needed to perform the task. In the programming world, polymorphism is used to make applications more modular and extensible. Instead of messy conditional statements describing different courses of action, you create interchangeable objects that you select based on your needs. That is the basic goal of polymorphism. --> Inheritance: Inheritance enables new classes to receive—or inherit—the properties and methods of existing classes. In previous articles, you learned that an object is a self-contained component that contains properties and methods needed to make a certain type of data useful. You also learned that a class is a blueprint or template to build a specific type of object and that every object is built from a class. Inheritance is a way to express a relationship between blueprints (classes). It's a way of saying: I want to build a new object that is similar to one that already exists, and instead of creating the new class from scratch, I want to reference the existing class and simply indicate what's different. Using two concepts of inheritance, subclassing (making a new class based on a previous one) and overriding (changing how a previous class works), you can organize your objects into a hierarchy. Using inheritance to make this hierarchy often creates easier to understand code, but most importantly it allows you to reuse and organize code more effectively.

In what order will the numbers 1-4 be logged to the console when the code below is executed? Why? (function() { console.log(1); setTimeout(function(){console.log(2)}, 1000); setTimeout(function(){console.log(3)}, 0); console.log(4); })();

1, 4, 3, 2 This has to do with how events are processes and a browser's event loop.

What is lazy loading?

--> Lazy loading means not creating an object until the first time it is accessed. --> Example: delays loading of images in long web pages. Images outside of viewport are not loaded until user scrolls to them. This is opposite of image preloading. Using Lazy Load on long web pages will make the page load faster.

What is Entity Framework?

--> Object relational mapping (ORM) using code first or model first. --> Takes care of relationships between tables for you.

Explain strongly typed vs other types of languages

--> Strong typing prevents mixing operations between mismatched types. In order to mix types, you must use an explicit conversion. --> Conversely, weak typing means that you can mix types without an explicit conversion.

What will the following code output? console.log(0.1 + 0.2); console.log(0.1 + 0.2 == 0.3);

0.3000000000000004 false false because 0.3 != 0.30000000000004 Why is this? Numbers are treated with floating point precision. They may not always yield the proper result.

What is the difference between an object and it's instance?

A blueprint for a house design is like a class description. All the houses built from that blueprint are objects of that class. A given house is an instance.

What is a class?

A class is a construct that enables you to create your own custom types by grouping together variables of other types, methods and events. A class is like a blueprint. It defines the data and behavior of a type. If the class is not declared as static, client code can use it by creating objects or instances which are assigned to a variable.

What is a "closure" in JavaScript? Provide an example.

A closure is an inner function that has access to the variables in the outer (enclosing) function's scope chain. The closure has access to variables in three scopes; specifically: (1) variable in its own scope, (2) variables in the enclosing function's scope, and (3) global variables. Example var globalVar = "xyz"; (function outerFunc(outerArg) { var outerVar = 'a'; (function innerFunc(innerArg) { var innerVar = 'b'; console.log( "outerArg = " + outerArg + "\n" + "innerArg = " + innerArg + "\n" + "outerVar = " + outerVar + "\n" + "innerVar = " + innerVar + "\n" + "globalVar = " + globalVar); })(456); })(123);

What is Mocha?

A serial test running framework using Nodejs.

What is ASP.NET WebAPI?

ASP.NET Web API is a framework that makes it easy to build HTTP services that reach a broad range of clients, including browsers and mobile devices. With WebAPI content negotiation, we can return data based on the client requests. What I mean is, if the client is requesting the data to be returned as JSON or XML, the WebAPI framework deals with the request type and returns the data appropriately based on the media type. By default WebAPI provides JSON and XML based responses. WebAPI is an ideal platform for building pure HTTP based services where the request and response happens with HTTP protocol. The client can make a GET, PUT, POST, and DELETE request and get the WebAPI response appropriately. In summary, the WebAPI is An HTTP Service Designed for broad reach Uses HTTP as an Application protocol, not a transport protocol

What is ASP.NET?

ASP.NET is an open source server-side Web application framework designed for Web development to produce dynamic Web pages. It was developed by Microsoft to allow programmers to build dynamic web sites, web applications and web services.

What is an abstract class?

Abstract classes are closely related to interfaces. They are classes that cannot be instantiated, and are frequently either partially implemented, or not at all implemented

Give a summary of what AJAX is and does

Ajax is short for asynchronous JavaScript and XML is a group of interrelated Web development techniques used on the client-side to create asynchronous Web applications. With Ajax, web applications can send data to and retrieve from a server asynchronously (in the background) without interfering with the display and behavior of the existing page. Data can be retrieved using the XMLHttpRequest object. Despite the name, the use of XML is not required (JSON is often used in the AJAJ variant), and the requests do not need to be asynchronous. Ajax is not a single technology, but a group of technologies. HTML and CSS can be used in combination to mark up and style information. The DOM is accessed with JavaScript to dynamically display - and allow the user to interact with - the information presented. JavaScript and the XMLHttpRequest object provide a method for exchanging data asynchronously between browser and server to avoid full page reloads.

What is an object?

An object can be a variable, a data structure, or a function. In the class-based object-oriented programming paradigm, "object" refers to a particular instance of a class where the object can be a combination of variables, functions, and data structures.

What is Big-"O" notation?

Big O notation is the language we use for articulating how long an algorithm takes to run. how quickly the runtime grows—Some external factors affect the time it takes for a function to run: the speed of the processor, what else the computer is running, etc. So it's hard to make strong statements about the exact runtime of an algorithm. Instead we use big O notation to express how quickly its runtime grows. relative to the input—Since we're not looking at an exact number, we need something to phrase our runtime growth in terms of. We use the size of the input. So we can say things like the runtime grows "on the order of the size of the input" (O(n)O(n)) or "on the order of the square of the size of the input" (O(n^2)O(n as the input gets arbitrarily large—Our algorithm may have steps that seem expensive when nn is small but are eclipsed eventually by other steps as nn gets huge. For big O analysis, we care most about the stuff that grows fastest as the input grows, because everything else is quickly eclipsed as nn gets very large. If you know what an asymptote is, you might see why "big O analysis" is sometimes called "asymptotic analysis."

What is Chai?

Chai is a assertion library that can be used with Mocha, giving you access to should, expect, and assert methods to run in your tests.

What is 'use strict' used for?

Disallows duplicate property names in objects, prevents accidental globals, debugging becomes easier due to errors being present that would've otherwise been ignored.

Explain Encapsulation

Encapsulation is a strategy used as part of abstraction. Encapsulation refers to the state of objects - objects encapsulate their state and hide it from the outside; outside users of the class interact with it through its methods, but cannot access the classes state directly. So the class abstracts away the implementation details related to its state. It is used to display only necessary and essential features of an object to outside the world. Means displaying what is necessary and encapsulate the unnecessary things to outside the world. Hiding can be achieved by using "private" access modifiers.

What is firebase?

Firebase is a NoSQL database that stores data as JSON documents.

What is the code first approach to databases?

Full control over the code (no auto-generated code which is hard to modify). General expectation is that you do not bother with DB. DB is just a storage with no logic. EF will handle creation and you don't want to know how it do the job. Manual changes to database will be most probably lost because your code defines the database.

How to detect the operating system on the client machine?

In order to detect the operating system on the client machine, the navigator.appVersion string (property) should be used.

Explain Inheritance

Inheritance enables new classes to receive—or inherit—the properties and methods of existing classes. In previous articles, you learned that an object is a self-contained component that contains properties and methods needed to make a certain type of data useful. You also learned that a class is a blueprint or template to build a specific type of object and that every object is built from a class. Inheritance is a way to express a relationship between blueprints (classes). It's a way of saying: I want to build a new object that is similar to one that already exists, and instead of creating the new class from scratch, I want to reference the existing class and simply indicate what's different. Using two concepts of inheritance, subclassing (making a new class based on a previous one) and overriding (changing how a previous class works), you can organize your objects into a hierarchy. Using inheritance to make this hierarchy often creates easier to understand code, but most importantly it allows you to reuse and organize code more effectively.

What is JavaScript?

Interpreted on the client-side (except in NodeJS). It is developed by Netscape Comm. Corp. and Sun Microsystems.

What is this keyword?

It refers to the current object.

What is MVC

MVC is a software architecture - the structure of the system - that separates domain/application/business (whatever you prefer) logic from the rest of the user interface. It does this by separating the application into three parts: the model, the view, and the controller. The model manages fundamental behaviors and data of the application. It can respond to requests for information, respond to instructions to change the state of its information, and even to notify observers in event-driven systems when information changes. This could be a database, or any number of data structures or storage systems. In short, it is the data and data-management of the application. The view effectively provides the user interface element of the application. It'll render data from the model into a form that is suitable for the user interface. The controller receives user input and makes calls to model objects and the view to perform appropriate actions. All in all, these three components work together to create the three basic components of MVC.

What is overloading?

Method Overloading is unrelated to polymorphism. It refers to defining different forms of a method (usually by receiving different parameter number or types). It can be seen as static polymorphism. The decision to call an implementation or another is taken at coding time. Notice in this case the signature of the method must change. Like in Visual Studio when you use a method, and IntelliSense gives you the ability to select between 5 or more overridden methods (all of which have different signatures).

What is the MVP pattern?

Model-view-presenter (MVP) is a derivation of the model-view-controller (MVC) architectural pattern, and is used mostly for building user interfaces. In MVP the presenter assumes the functionality of the "middle-man". In MVP, all presentation logic is pushed to the presenter. The model is an interface defining the data to be displayed or otherwise acted upon in the user interface. The view is a passive interface that displays data (the model) and routes user commands (events) to the presenter to act upon that data. The presenter acts upon the model and the view. It retrieves data from repositories (the model), and formats it for display in the view.

Will these two functions return that same thing? function foo1() { return { bar: "hello" }; } function foo2() { return { bar: "hello" }; }

No. The first will return 'hello' whereas the second function with return undefined.

What are the primitive data types?

Null, undefined, boolean, string, number

What is OOP?

Object Oriented Programming languages are defined by the following key words: abstraction, encapsulation, inheritance, and polymorphism. An object is a container of data and functions that affect the data. In an OOP, a "child" object can "extend" another object (making it more specific) by inheriting from a "parent" object. Thus the child gets all the parents data and functionality "for free". The idea of an "interface" is also key to OOPs. An interface is the allowed interactions between the outside world (e.g., other programs) and the object itself.

Explain Polymorphism

Polymorphism describes a pattern in object oriented programming in which classes have different functionality while sharing a common interface. The beauty of polymorphism is that the code working with the different classes does not need to know which class it is using since they're all used the same way. A real world analogy for polymorphism is a button. Everyone knows how to use a button: you simply apply pressure to it. What a button "does," however, depends on what it is connected to and the context in which it is used — but the result does not affect how it is used. If your boss tells you to press a button, you already have all the information needed to perform the task. In the programming world, polymorphism is used to make applications more modular and extensible. Instead of messy conditional statements describing different courses of action, you create interchangeable objects that you select based on your needs. That is the basic goal of polymorphism.

What is QUnit?

QUnit is a JavaScript unit testing framework. While heavily used by the jQuery Project for testing jQuery, jQuery UI and jQuery Mobile, it is a generic framework to test any JavaScript code.

What does "1"+2+4 evaluate to?

Since 1 is a string, everything is a string, so the result is 124.

What does2+5+"8" evaluate to?

Since 2 and 5 are integers, this is number arithmetic, since 8 is a string, it's concatenation, so 78 is the result.

What is Javascript namespacing? How and where is it used?

That being said, namespacing is used to bundle up all your functionality using a unique name. In JavaScript, a namespace is really just an object that you've attached all further methods, properties and objects. It promotes modularity and code reuse in the application.

What is the repository pattern?

The Repository Pattern is a common construct to avoid duplication of data access logic throughout our application. This includes direct access to a database, ORM, WCF dataservices, xml files and so on. The sole purpose of the repository is to hide the nitty gritty details of accessing the data. We can easily query the repository for data objects, without having to know how to provide things like a connection string. The repository behaves like a freely available in-memory data collection to which we can add, delete and update objects. The Repository pattern adds a separation layer between the data and domain layers of an application. It also makes the data access parts of an application better testable.

What is the difference between an object and a class?

The class = the blue print. The Object is an actual thing that is built based on the 'blue print' (like the house). An instance is a virtual copy (but not a real copy) of the object.

JS: Difference between == and === ?

The double equal will convert types and THEN check for equality. The triple equal will return false immediately if the types are different.

Difference between document load event and document ready event?

The load event will take longer, because it waits for everything to be loaded (like HTML/DOM/Images etc). Where as document ready simply waits for the DOM/HTML file to be loaded, but not for the assets to be fully loaded as well.

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.

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. That isnt what we want. We just want to wait until the DOM is loaded and is able to be manipulated. onDocumentReady allows the programmer to do that.

What is the significance of, and reason for, wrapping the entire content of a JavaScript source file in a function block?

This prevents leaking global variables from ever reaching other parts of the application.

Pros and Cons of using an ORM?

Using an ORM save a lot of time because : DRY : You write your data model in only one place, it's easier to update, maintain and reuse the code. A lot of stuff is done automatically, from the database handling to I18N. It forces you to write MVC code, and in the end your app is cleaner. You don't have to write poorly formed SQL (most Web programmers really suck at it, because SQL is treated like a "sub" language whereas it's a very powerful and complex one) Sanitizing, using prepared statements or transactions are as easy as calling a method. Using an ORM is more flexible because : It fits in your natural way of coding (it's your language !) It abstracts the DB system, so you can change it whenever you want. The model is weakly binded to the rest of the app, so you can change it or use it anywhere else. It let you use OOP goodness like data inheritance without head ache. But ORM can be a pain : You have to learn it, and they are not lightweight tools; You have to set it up. Same problem. Performances are ok for usual queries, but a SQL master will always do better with his little hands for the big dirty works. It abstracts the DB. While it's ok if you know what's happening behind the scene, it's a trap for the noobs that can write very greedy statements, like a heavy hit in a for loop...

How is form submission possible via javascript?

We can achieve the desired form submission by using the function document.forms[0].submit(). If there are multiple forms on a page, we simply increment the index of the forms array.

Why use == over ===?

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

How is JavaScript different from Java?

While both share common syntax, both have much different use cases. JavaScript relies on the browser or whatever environment it's in whereas Java is a compiled language.

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

Yes, using the 'typeof' keyword

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

arr[arr.length] = value;, array.push(), array.unshift()

What will this return? var myObject = { foo: "bar", func: function() { var self = this; console.log("outer func: this.foo = " + this.foo); console.log("outer func: self.foo = " + self.foo); (function() { console.log("inner func: this.foo = " + this.foo); console.log("inner func: self.foo = " + self.foo); }()); } }; myObject.func();

bar bar undefined bar The 'this' keyword has changed context since being called inside of an ifee.

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

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

What is NaN? What is its type? How can you reliably test if a value is equal to NaN?

he NaN property represents a value that is "not a number". This special value results from an operation that could not be performed either because one of the operands was non-numeric (e.g., "abc" / 4), or because the result of the operation is non-numeric (e.g., an attempt to divide by zero). ES6 can simply use isNaN()

How do you assign object properties?

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

What is ORM?

object relational mapping: a programming technique for converting data between incompatible type systems in object-oriented programming languages. This creates, in effect, a "virtual object database" that can be used from within the programming language

What are two JavaScript timers?

setTimeout and setInterval. setTimeout will execute a function after a delay. setInterval will execute repeatedly and only stops when canceled with clearTimeout(id)

Explain Abstraction

the process of identifying common patterns that have systematic variations; an abstraction represents the common pattern and provides a means for specifying which variation to use.

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.

Write a one line function that returns whether or not a word is a Palindrome.

var w = 'racecar'; function bool(word){ return word.split('').reverse().join('') === word; }


Conjuntos de estudio relacionados

Servsafe ch 7 - The Flow of Food: Service

View Set

Microeconomics Study Guide Answers

View Set

NU144- Chapter 68: Management of Patients With Neurologic Trauma

View Set

World History Ch. 20 Test Review (Philp)

View Set

lung, skin, colorectal, prostate

View Set