Skip to content

Instantly share code, notes, and snippets.

View AkimaLunar's full-sized avatar

Aaron Carmin AkimaLunar

  • Vancouver Island, BC
  • 07:31 (UTC -07:00)
View GitHub Profile
@AkimaLunar
AkimaLunar / Mongo-basics-drills.md
Last active June 3, 2017 04:05
Mongo basics drills

Get all

db.restaurants.find()

Limit and sort

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})

Get by _id

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);
}

Variable Scope

What is scope? Your explanation should include the idea of global vs. local scope.

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

Why are global variables avoided?

You or another developer can accidentally write code that mutates or overwrites a global variable from a local scope.

Explain JavaScript's strict mode

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.