db.restaurants.find()
Find the command that makes the first 10 restaurants appear when db.restaurants is alphabetically sorted by the name property.
db.restaurants.find().limit(10).sort({name:1})
function getTokens(rawString) { | |
// This is a pure function that takes a string and returns an array. | |
// First, all characters are set to lower case. Then, the string is | |
// separated into segments when one of these characters is encountered: | |
// ,!.";:- or a whitespace. The function filtes out all segments that are | |
// 0, empty string, null, undefined or NaN. Finally, the array is sorted | |
// with the default, Unicode code point order. | |
return rawString.toLowerCase().split(/[ ,!.";:-]+/).filter(Boolean).sort(); |
function timer(t){ | |
setTimeout(function() { | |
console.log('Right timer: ' + t +'s'); | |
}, t * 1000 ); | |
} | |
for (var i = 0; i < 5; i++) { | |
timer(i); | |
} |
Scope defines the visibility of variables. In JavaScript, variables can be in either global or local scope. Global variables are accissible from anywhere in the application. Local variables declared with a var
keyword are visible only within a function block. Local variables declared with let
keyword are limited further to their respective block, statement or expression
You or another developer can accidentally write code that mutates or overwrites a global variable from a local scope.
JavaScript's strict mode allows the developer to opt-in a more restrictive version of JavaScript. Mistakes that would normally just silently fail, would throw an error in the strict mode.