Last active
August 29, 2015 13:56
-
-
Save Cycymomo/8847976 to your computer and use it in GitHub Desktop.
quiz-dvp-hardcore.js
This file contains hidden or 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
/////////////////////////////////////////// | |
// Question 1 | |
// D'après le code suivant, que retournera go() ? | |
var x = 3; | |
var foo = { | |
x: 2, | |
baz: { | |
x: 1, | |
bar: function() { | |
return this.x; | |
} | |
} | |
} | |
var go = foo.baz.bar; | |
// Possibilité : 1, 2, 3, undefined | |
// Réponse : console.log(go()); // 3. | |
// Selon le code précédent, que retournera foo.baz.bar() ? | |
// Possibilité : 1, 2, 3, undefined | |
// Réponse : console.log(foo.baz.bar()); // 1 | |
/////////////////////////////////////////// | |
// Question 2 | |
// D'après le code suivant, que vaut bar.x ? | |
var x = 0; | |
function foo() { | |
x++; | |
this.x = x; | |
return foo; | |
} | |
var bar = new new foo(); | |
// Possibilité : 0, 1, undefined, TypeError: undefined is not a function | |
// Réponse : console.log(bar.x); // undefined | |
/////////////////////////////////////////// | |
// Question 3 : | |
// D'après le code suivant, que vaut b ? | |
function foo(a, b) { | |
arguments[1] = 2; | |
console.log(b); // que vaut b à cet instant ? | |
} | |
foo(1); | |
// Possibilité : 2, null, undefined | |
// Réponse : undefined. Alors que si on avait exécuté foo(1,'une valeur quelconque');, b aurait valu 2 | |
/////////////////////////////////////////// | |
// Question 4 : | |
// D'après le code suivant, que vaut typeof foo() ? | |
function foo() { | |
return | |
{ | |
val: 1 | |
}; | |
} | |
// Possibilité : "function", "undefined", "object", undefined | |
// Réponse : console.log(typeof foo()); // "undefined". Notez le retour à la ligne après return. Sans ce retour, le résultat aurait été "object". De plus, l'opérateur unaire typeof retourne toujours une string. | |
/////////////////////////////////////////// | |
// Question 5 : | |
// D'après le code suivant, que vaut foo.baz + foo.bar + bar; ? | |
var bar = 1, | |
foo = {}; | |
foo: { | |
bar: 2; | |
baz: ++bar; | |
}; | |
foo.baz + foo.bar + bar; // ? | |
// Possibilité : TypeError, undefined, NaN, 4, 5, 6 | |
// Réponse : NaN. Faites attention à la syntaxe. Ici on ne définit pas l'objet foo mais on crée des "label".https://developer.mozilla.org/fr/docs/XUL/label | |
/////////////////////////////////////////// | |
// Question 6 : | |
// D'après le code suivant, que vaut x ? | |
var x; | |
x = 1,000,000; | |
// Possibilité : 0, 1, undefined | |
// Réponse : 1. Si vous exécutez ce code, 0 est retourné. En effet, une suite d'expression avec l'opérateur ',' retourne le dernier, soit 000, donc 0. Alors que 1 est bien assigné à x. | |
// voir : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment