What ‘use strict’ Good For?

  • Makes debugging easier - shows error messages that otherwise won’t be shown
  • Prevents accidental globals - declaration of variables w/o var
  • Eliminates this coercion - null or undefined references won’t be automatically coerced to the global.
  • Disallows duplicate property names or parameter values - var object = {foo: "bar", foo: "baz"}; or function foo(val1, val2, val1){} are not allowed
  • Makes eval() safer - statements variables declared inside eval stay there
  • Throws error on invalid usage of delete - operator is not allowed on non-configurable parameters

Source: 16 Great JavaScript Interview Questions

ECMAScript 5 Array Methods

// Do all elements satisfy predicate?

// Return a new array with the elements that satisfy predicate?

// Call action(element) for each element

// What is the index of the first element that equals value?
Array.prototype.indexOf(value, fromIndex)

// What is the index of the last element that equal value?
Array.prototype.lastIndexOf(value, fromIndex)

// Create a new array by applying unaryFunc to each element

// Reduces the elements of the array, by applying binaryFunc between the elements [a0, a1].reduce(+ , seed) == seed + a0 + a1
Array.prototype.reduce(binaryFunc, seed)

// Is at least one element satisfied by the predicate? Array.prototype.some(predicate)

Use Dropbox As a Web Server. Kinda.

  • Dropbox can serve files over HTTP
  • To view the file over http users don’t need to have any Dropbox account
  • You can share only static web resources pages, e.g. HTML, CSS, JS and images, of course
  • For images Dropbox sends header cache-control: max-age=0. That means that images are not cached at client side.
  • Dropbox also generates content type header based on file extension. e.g. for png files it send the header Content-Type:image/png
  • Everything in Public Folder is automatically shared and generates a URL
  • Files and folders from locations other than Public Folders can also be shared

Source: How to use dropbox as mini webserver

AngularJS Directive’s Scope

scope:falseDirective uses its parent scope. Changes are reflected in both parent & child

scope:true - Directive gets a new scope. Changes are reflected only in child but not in parent

scope:{} - Directive gets a new isolated scope. No inheritance & changes are not reflected at all.

In the third option, we need to declare parameters in order to pass values from parent:

scope: {
    name: ‘@’, // expression
    age: ‘=’,     // model name
    emailAddress: ‘&’   // method

<user-card class=”myClass” name=”{{ myName }}” age=”myAge” email-address=”getMyMail()” />

@ - Text binding / one-way binding
= - Direct model binding / two-way binding
& - Behavior binding / Method binding

Source: Mastering the Scope of the Directives in AngularJS