Last active
November 15, 2018 13:47
-
-
Save kutyel/87ca38574b9375c8df91bd8df2fa8bb3 to your computer and use it in GitHub Desktop.
Skype Technical Interview's Questions about JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Write a JavaScript function that takes a number n and returns the sum of the even numbers from 1 to n. | |
*/ | |
function firstFunc(n) { | |
let result = 0; | |
for (let index = 1; index <= n; index++) { | |
if (index % 2 === 0) { | |
result += index; | |
} | |
} | |
return result; | |
} | |
/** | |
* Write a function that takes an integer n and returns the next number greater than n that is a multiple of 7. | |
*/ | |
function secondFunc(n) { | |
if (n < 7) { return 7; } | |
for (var aux = 1; aux * 7 <= n; aux++) {} | |
return aux * 7; | |
} | |
/** | |
* Write the "Factorial" function recursively, without using a loop: "function factorial ( n ) {…}" | |
* (A factorial is the product of a positive number and all the numbers below it. | |
* So the factorial of 4 equals 4 x 3 x 2 x 1 = 24. The factorial of 1 equals 1.) | |
*/ | |
function factorial(n) { | |
return n > 1 ? n * factorial(n - 1) : 1; | |
} | |
/** | |
* What would this function return? | |
* | |
* Returns `undefined`. | |
*/ | |
function foo() { | |
return | |
{ | |
bar: "hello" | |
}; | |
} | |
/** | |
* What is a "closure" in JavaScript? | |
* | |
* Closures are functions that refer to independent (free) variables (variables that are used locally, | |
* but defined in an enclosing scope). In other words, these functions 'remember' the environment in which they were created. | |
*/ | |
(function init(name) { | |
(function displayName() { | |
alert(name); | |
})(); | |
})('Flavio'); | |
/** | |
* How does the "this" keyword work in JavaScript? | |
* | |
* See this link http://javascriptissexy.com/understand-javascripts-this-with-clarity-and-master-it/ for a full-detail explanation. | |
*/ | |
/** | |
* What do the "apply" and "call" functions do? What are the differences between the two? | |
* | |
* The `apply()` method calls a function with a given `this` value and arguments provided as an array (or an array-like object). | |
* The `call()` method calls a function with a given `this` value and arguments provided individually. | |
* While the syntax of this function is almost identical to that of `call()`, | |
* the fundamental difference is that `call()` accepts an argument list, while `apply()` accepts a single array of arguments. | |
*/ | |
function log(x, y, z) { | |
console.log(x, y, z); | |
} | |
var args = [1, 2, 3]; | |
log.apply(null, args); // with `apply()` | |
log.call(null, ...args); // with `call()` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment