Coding Journal

Jordan Vidrine

Daily Coding Journal

An experienced business owner + musician with a demonstrated history of management in the Energy sector and an insatiable appetite for learning new and complex skills. Transitioning from an ownership role & seeking employment in Web Development as a Jr Full Stack Developer.

May 29th 2019

Went through chapter 1 of Build Your Own Angular again to solidify the javascript examples and knowledge.

Noticed three things that stood out for me.

  1. Explicitly returning false in a LoDash forEach loop causes loDash to to exit the loop immediately.

  2. A double negation ie. !!value will coerce it into a real boolean if the value isn’t something immediately convertible into a true/false value ie. !!undefined = false

  3. This return syntax is a little complicated to me

      // true or false??     OR   ???   how can you return true or false OR another true or false
return newValue === oldValue || (typeof newValue === 'number' && typeof oldValue === 'number'  && isNaN(newValue) && isNaN(oldValue));

The issues we are dealing with in this chapter is creating a ‘watcher’ that will invoke a function if that item it is watching is changed. If the item happens to be an array or object, it is necessary (if the user specifies) to check each value in that object or array.

Value-based dirty-checking implies that if the old or new values are objects or arrays we have to iterate through everything contained in them. If there’s any difference in the two values, the watcher is dirty. If the value has other objects or arrays nested within, those will also be recursively compared by value.

Back to blog...