SlideShare a Scribd company logo
Javascript Quiz
Technical questions to ask when recruiting developers.

Alberto Naranjo
Jan. 2014
OOP
What’s prototyping?
Javascript does’nt use classical ‘inheritance’ model. It uses
prototypal inheritance. We will want to declare methods on the
prototype class, not in the constructor, mainly because when the
use new the object would create each time a new copy of the
methods instead of using the common one from the prototype.
//Guitar function constructor
function Guitar(color, strings) {
this.color = color;
this.strings = strings;
}
//Guitar prototype method
Guitar.prototype.play = function(chord){
return chord;
}
var myguitar = new Guitar(‘blue’,[‘A’,’F’,’G’]);
--------Guitar.prototype = {
play : function(chord){ return chord; },
getColor : function(){ return this.color; }
};
How to create objects with properties?
Also add a function as a property.

var man = new Object();
man.name = ‘Alberto Naranjo’;
man.getName = function(){ return this.name; }
console.log(man.getName()); //logs Alberto Naranjo
Implement dot and literals object
notation. What’s the difference?

There is no practical difference.
var man = new Object();
man.name = “Albert”; // man[‘name’] = “Albert”;
man.age = 29; // man[‘age’] = 29;
---------var man = { ‘name’ : “Andrew”, ‘age’ : 27 };
Inheritance, how can you do
it in JS? :)
Simple guide to inheritance:
http://phrogz.net/JS/classes/OOPinJS2.html
Cat.prototype = new Mammal(); //Inheritance occurs
Cat.prototype.constructor = Cat; //Override new constructor
function Cat(name){ this.name=name; } //New constructor
//We can override any method, and inherit old methods.
General Syntax
What’s event bubbling and event
propagation. How to stop propagation?
Event bubbling describe the behavior of events in child and
parents nodes in the Document Object Model. The child
pass their events to their parents nodes. The main benefit of
this behavior is the speed because the code has to traverse
the DOM tree only once. And simplicity because you only
need one event listener for all children nodes. For example, a
click event listener in page’s body element, will trigger on
any click of the inner components. Event capturing also
called bubble down. Where outer elements events trigger
before inner (parents before children).
event.stopPropagation();
event.cancelBubble = true; //for IE<9
Implement dynamic function
calling using dynamic parameters.

var myDynamicFunc = (function(text){ alert(text); })(‘Hello!’);
What’s a closure? Implement
an example.
A closure is an inner function with 3 scopes: local
variables, outer variables and global variables.
function showName (firstName, lastName) {
var nameIntro = "Your name is ";
//this inner function has access to the outer function's variables, including params
function makeFullName () {
return nameIntro + firstName + " " + lastName;
}
return makeFullName ();
}
showName ("Michael", "Jackson"); // Your name is Michael Jackson
Explain differences between ==
and ===. Implement an example.
Briefly == will only check for the value, and === (strict
equality) will check also for the type/object without
type conversion. When comparing objects === will
return false if they are not the same pointer/reference
to the same object even if the have the same value.
object1 = new Number(‘10’);
object2 = new Number(‘10’);
object3 = object2;
console.log(object1 === object2); //false
console.log(object2 === object3); //true
Global vs local variable
definition. Implement both.
Related to the scope, a global variable has no scope
and it’s available on any place of the code. Good
programmer should avoid it in all situations. A local
variable has a local scope, inside a object, block or
structure.
globalvar=true;
var localvar=true;
How the this keyword works?

In Javascript the this keyword usually references the
object who owns the method. But depending on the
scope. Sometimes you use this in reference to the
Window object. When working with event handlers
this references the object who created the event.
How do you do error
handling in JS? Implement.
You can use the structure try-catch-finally to manage
the error handling.
try {
//do something.
} catch(e) {
console.log(e.message);
document.write ("Error Message: " + e.message);
document.write ("<br />");
document.write ("Error Code: ");
document.write (e.number & 0xFFFF);
document.write ("<br />");
document.write ("Error Name: " + e.name);
} finally {
//do something always.
}
Enumerate all Javascript
types.
1. Number
2. Boolean
3. String
4. Object
5. function
6. null
7. undefined
How timers work? What you
should be aware of?
They run in a single thread so there would be events
in queue.
setTimeout(function, miliseconds);
------var id = setInterval(function, miliseconds);
clearInterval(id);
How do you read or modify any
property from a DOM element?

var myProperty = document.getElementById(‘id’).property;
document.getElementById(‘id’).value = ‘Hello!’;
Arrays
Implement a simple array
with 3 elements

var myArray = new Array(‘a’,’b’,’c’);
Implement an associative
array.
I will use a literal object notation to create one.

var myArray={key1: 'value1', key2:'value2' };
alert(myArray[‘key1’]); // Also myArray.key1
There is such for-each block
in Javascript?
There is one, but it’s not fully supported. You can use
also for-in structure.
a.forEach( function(entry) { console.log(entry); });
------var key;
for (key in a) {
console.log(a.key);
}
Suggest more
questions ;)

More Related Content

DOC
DOCX
Top Javascript Q's
PDF
Of complicacy of programming, or won't C# save us?
PDF
Intro to JavaScript
PDF
Midiendo la calidad de código en WTF/Min (Revisado EUI Abril 2014)
PDF
Advanced javascript
PPT
Svcc Building Rich Applications with Groovy's SwingBuilder
PDF
JavaScript Core
Top Javascript Q's
Of complicacy of programming, or won't C# save us?
Intro to JavaScript
Midiendo la calidad de código en WTF/Min (Revisado EUI Abril 2014)
Advanced javascript
Svcc Building Rich Applications with Groovy's SwingBuilder
JavaScript Core

What's hot (20)

PPT
Qtp not just for gui anymore
PPT
Svcc Groovy Testing
PDF
Headless Js Testing
PPT
Svcc Java2D And Groovy
PPTX
Intro to Javascript
PDF
Analyzing FreeCAD's Source Code and Its "Sick" Dependencies
PPT
JavaScript Basics
PPTX
Introduction to Grails Framework
PPT
CodeMash - Building Rich Apps with Groovy SwingBuilder
DOCX
Informatics Practice Practical for 12th class
PDF
JavaScript 101
PDF
ES3-2020-P3 TDD Calculator
ODP
Object Oriented Javascript
PPTX
Typescript tips & tricks
PDF
One Year of Clean Architecture - The Good, The Bad and The Bob
PDF
Javantura v2 - Making Java web-apps Groovy - Franjo Žilić
PPT
JavaScript - An Introduction
PDF
Basics of JavaScript
PDF
Anonymous functions in JavaScript
PDF
Java vs. C/C++
Qtp not just for gui anymore
Svcc Groovy Testing
Headless Js Testing
Svcc Java2D And Groovy
Intro to Javascript
Analyzing FreeCAD's Source Code and Its "Sick" Dependencies
JavaScript Basics
Introduction to Grails Framework
CodeMash - Building Rich Apps with Groovy SwingBuilder
Informatics Practice Practical for 12th class
JavaScript 101
ES3-2020-P3 TDD Calculator
Object Oriented Javascript
Typescript tips & tricks
One Year of Clean Architecture - The Good, The Bad and The Bob
Javantura v2 - Making Java web-apps Groovy - Franjo Žilić
JavaScript - An Introduction
Basics of JavaScript
Anonymous functions in JavaScript
Java vs. C/C++
Ad

Viewers also liked (8)

DOCX
Bit%20 ch02
PDF
Javascript quiz
PPTX
Chapter 4 Programs and Apps
PDF
21 Essential JavaScript Interview Questions
PPTX
Chapter 3 Computers and Mobile Devices
DOC
Mcq of e comm
PDF
Html interview-questions-and-answers
PDF
TEDx Manchester: AI & The Future of Work
Bit%20 ch02
Javascript quiz
Chapter 4 Programs and Apps
21 Essential JavaScript Interview Questions
Chapter 3 Computers and Mobile Devices
Mcq of e comm
Html interview-questions-and-answers
TEDx Manchester: AI & The Future of Work
Ad

Similar to Javascript quiz. Questions to ask when recruiting developers. (20)

PPTX
Awesomeness of JavaScript…almost
PDF
Rediscovering JavaScript: The Language Behind The Libraries
PPT
Object Oriented JavaScript
KEY
Javascript tid-bits
PDF
JavaScript Primer
PDF
Js in-ten-minutes
PDF
Scalable JavaScript
PPTX
All of Javascript
PPTX
Object oriented java script
PPTX
All of javascript
PDF
JavaScript
PPT
JavaScript - Programming Languages course
PPTX
Java script
PDF
22519 - Client-Side Scripting Language (CSS) chapter 1 notes .pdf
PDF
Pragmatic JavaScript
PPTX
Lecture 5: Client Side Programming 1
PDF
PPT
Basic Javascript
PPTX
Art of Javascript
PPTX
JavaScript Fundamentals & JQuery
Awesomeness of JavaScript…almost
Rediscovering JavaScript: The Language Behind The Libraries
Object Oriented JavaScript
Javascript tid-bits
JavaScript Primer
Js in-ten-minutes
Scalable JavaScript
All of Javascript
Object oriented java script
All of javascript
JavaScript
JavaScript - Programming Languages course
Java script
22519 - Client-Side Scripting Language (CSS) chapter 1 notes .pdf
Pragmatic JavaScript
Lecture 5: Client Side Programming 1
Basic Javascript
Art of Javascript
JavaScript Fundamentals & JQuery

Recently uploaded (20)

PDF
Unit 1 Cost Accounting - Cost sheet
PDF
MSPs in 10 Words - Created by US MSP Network
PDF
Business model innovation report 2022.pdf
PPTX
ICG2025_ICG 6th steering committee 30-8-24.pptx
PDF
Katrina Stoneking: Shaking Up the Alcohol Beverage Industry
PDF
Ôn tập tiếng anh trong kinh doanh nâng cao
PPTX
Belch_12e_PPT_Ch18_Accessible_university.pptx
PPTX
HR Introduction Slide (1).pptx on hr intro
PDF
pdfcoffee.com-opt-b1plus-sb-answers.pdfvi
DOCX
Business Management - unit 1 and 2
PPTX
job Avenue by vinith.pptxvnbvnvnvbnvbnbmnbmbh
PDF
Traveri Digital Marketing Seminar 2025 by Corey and Jessica Perlman
PDF
COST SHEET- Tender and Quotation unit 2.pdf
PDF
A Brief Introduction About Julia Allison
PDF
SIMNET Inc – 2023’s Most Trusted IT Services & Solution Provider
PDF
20250805_A. Stotz All Weather Strategy - Performance review July 2025.pdf
PPTX
Lecture (1)-Introduction.pptx business communication
PDF
WRN_Investor_Presentation_August 2025.pdf
PDF
Nidhal Samdaie CV - International Business Consultant
PPTX
Dragon_Fruit_Cultivation_in Nepal ppt.pptx
Unit 1 Cost Accounting - Cost sheet
MSPs in 10 Words - Created by US MSP Network
Business model innovation report 2022.pdf
ICG2025_ICG 6th steering committee 30-8-24.pptx
Katrina Stoneking: Shaking Up the Alcohol Beverage Industry
Ôn tập tiếng anh trong kinh doanh nâng cao
Belch_12e_PPT_Ch18_Accessible_university.pptx
HR Introduction Slide (1).pptx on hr intro
pdfcoffee.com-opt-b1plus-sb-answers.pdfvi
Business Management - unit 1 and 2
job Avenue by vinith.pptxvnbvnvnvbnvbnbmnbmbh
Traveri Digital Marketing Seminar 2025 by Corey and Jessica Perlman
COST SHEET- Tender and Quotation unit 2.pdf
A Brief Introduction About Julia Allison
SIMNET Inc – 2023’s Most Trusted IT Services & Solution Provider
20250805_A. Stotz All Weather Strategy - Performance review July 2025.pdf
Lecture (1)-Introduction.pptx business communication
WRN_Investor_Presentation_August 2025.pdf
Nidhal Samdaie CV - International Business Consultant
Dragon_Fruit_Cultivation_in Nepal ppt.pptx

Javascript quiz. Questions to ask when recruiting developers.

  • 1. Javascript Quiz Technical questions to ask when recruiting developers. Alberto Naranjo Jan. 2014
  • 2. OOP
  • 3. What’s prototyping? Javascript does’nt use classical ‘inheritance’ model. It uses prototypal inheritance. We will want to declare methods on the prototype class, not in the constructor, mainly because when the use new the object would create each time a new copy of the methods instead of using the common one from the prototype. //Guitar function constructor function Guitar(color, strings) { this.color = color; this.strings = strings; } //Guitar prototype method Guitar.prototype.play = function(chord){ return chord; } var myguitar = new Guitar(‘blue’,[‘A’,’F’,’G’]); --------Guitar.prototype = { play : function(chord){ return chord; }, getColor : function(){ return this.color; } };
  • 4. How to create objects with properties? Also add a function as a property. var man = new Object(); man.name = ‘Alberto Naranjo’; man.getName = function(){ return this.name; } console.log(man.getName()); //logs Alberto Naranjo
  • 5. Implement dot and literals object notation. What’s the difference? There is no practical difference. var man = new Object(); man.name = “Albert”; // man[‘name’] = “Albert”; man.age = 29; // man[‘age’] = 29; ---------var man = { ‘name’ : “Andrew”, ‘age’ : 27 };
  • 6. Inheritance, how can you do it in JS? :) Simple guide to inheritance: http://phrogz.net/JS/classes/OOPinJS2.html Cat.prototype = new Mammal(); //Inheritance occurs Cat.prototype.constructor = Cat; //Override new constructor function Cat(name){ this.name=name; } //New constructor //We can override any method, and inherit old methods.
  • 8. What’s event bubbling and event propagation. How to stop propagation? Event bubbling describe the behavior of events in child and parents nodes in the Document Object Model. The child pass their events to their parents nodes. The main benefit of this behavior is the speed because the code has to traverse the DOM tree only once. And simplicity because you only need one event listener for all children nodes. For example, a click event listener in page’s body element, will trigger on any click of the inner components. Event capturing also called bubble down. Where outer elements events trigger before inner (parents before children). event.stopPropagation(); event.cancelBubble = true; //for IE<9
  • 9. Implement dynamic function calling using dynamic parameters. var myDynamicFunc = (function(text){ alert(text); })(‘Hello!’);
  • 10. What’s a closure? Implement an example. A closure is an inner function with 3 scopes: local variables, outer variables and global variables. function showName (firstName, lastName) { var nameIntro = "Your name is "; //this inner function has access to the outer function's variables, including params function makeFullName () { return nameIntro + firstName + " " + lastName; } return makeFullName (); } showName ("Michael", "Jackson"); // Your name is Michael Jackson
  • 11. Explain differences between == and ===. Implement an example. Briefly == will only check for the value, and === (strict equality) will check also for the type/object without type conversion. When comparing objects === will return false if they are not the same pointer/reference to the same object even if the have the same value. object1 = new Number(‘10’); object2 = new Number(‘10’); object3 = object2; console.log(object1 === object2); //false console.log(object2 === object3); //true
  • 12. Global vs local variable definition. Implement both. Related to the scope, a global variable has no scope and it’s available on any place of the code. Good programmer should avoid it in all situations. A local variable has a local scope, inside a object, block or structure. globalvar=true; var localvar=true;
  • 13. How the this keyword works? In Javascript the this keyword usually references the object who owns the method. But depending on the scope. Sometimes you use this in reference to the Window object. When working with event handlers this references the object who created the event.
  • 14. How do you do error handling in JS? Implement. You can use the structure try-catch-finally to manage the error handling. try { //do something. } catch(e) { console.log(e.message); document.write ("Error Message: " + e.message); document.write ("<br />"); document.write ("Error Code: "); document.write (e.number & 0xFFFF); document.write ("<br />"); document.write ("Error Name: " + e.name); } finally { //do something always. }
  • 15. Enumerate all Javascript types. 1. Number 2. Boolean 3. String 4. Object 5. function 6. null 7. undefined
  • 16. How timers work? What you should be aware of? They run in a single thread so there would be events in queue. setTimeout(function, miliseconds); ------var id = setInterval(function, miliseconds); clearInterval(id);
  • 17. How do you read or modify any property from a DOM element? var myProperty = document.getElementById(‘id’).property; document.getElementById(‘id’).value = ‘Hello!’;
  • 19. Implement a simple array with 3 elements var myArray = new Array(‘a’,’b’,’c’);
  • 20. Implement an associative array. I will use a literal object notation to create one. var myArray={key1: 'value1', key2:'value2' }; alert(myArray[‘key1’]); // Also myArray.key1
  • 21. There is such for-each block in Javascript? There is one, but it’s not fully supported. You can use also for-in structure. a.forEach( function(entry) { console.log(entry); }); ------var key; for (key in a) { console.log(a.key); }