Road to JavaScript #3

3592 days ago, 0 views.

Truth, Equality in JavaScript and CoffeeScript

In JavaScript the truth of things is a little crazy.

""           ==   "0"           // false
0            ==   ""            // true
0            ==   "0"           // true
false        ==   "false"       // false
false        ==   "0"           // true
false        ==   undefined     // false
false        ==   null          // false
null         ==   undefined     // true
" \t\r\n"    ==   0             // true

For reduce issues in CoffeeScript exists two helpers:

This is nice and is sugar for you, but warning with use existential operators with Boolean values:

isUserExist = false
message = if isUserExist? then 'user exists!' else 'user doesn\'t exist!'
console.log message
# => "user exists!"

Because isUserExist is false and ? operator only returns false with null and undefined!

Another example with ||= and ?= operator:

# ||= operator
variable = false
variable ||= 'value'
variable # => 'value'

# ?= operator
variable2 = false
variable2 ?= 'value'
variable2 # => false

Always is important know the values that things in JavaScript can return. To know it I recommend check truth, equality and JavaScript and Better JS equality table.

JavaScript Application Architecture On The Road To 2015

A very nice post by @addyosmani explaning some tips and orientations for the future of the web.

Personally I think that 2015 is the year of databases anywhere, in special in the client side with projects very interesting as PouchDB or MeteorJS.

About ECMAScript 6 features is true that some features are now available, but still need too much effort to be consolidated in this new year.

Front-end Job Interview Questions

A fun and useful repository for measuring yourself about your knowledge in technologies in the frontend (and maybe as preparation for jobs interview!). Check it out in Github.

Functional JavaScript

For a long time I am interested in have a code a little more functional approach.

If you are interested I recommend yout start with this awesome introductional video by @javiervelezreye (at this moment only available in spanish, sorry):

In your code, exist some useful libraries to have this approach. Remember that pure functional code cannot mutate, and do it in vanilla JavaScript is maybe impossible because is too dynamic code. For do it, I recommend you check immutable-js by Facebook. Also provides you a type of collections that doesn’t exist in JavaScript at this moment, as Map or Set.

Definetely the right way to learn more about Functional Programming is try a pure functional language. ClojureScript is the language, and maybe for a first introduction Clojurescript Koans or modern-cljs may be appropriate (Yes, I still want to try, where is my time?)

About this, another useful library for JavaScript inspired in ClojureScript is transducers.js that allow you use Clojure approach in JavaScript. To understand better check the author’s post one and two.

Client, memory and Databases

Recently @rcsole_ show me the power of levelDB. At this moment @substack is writting a little book, but still needs some time to get ready.

Anyway, the thing that most impacted me is how the projects is organize. Originally levelDB is a Google Project written in C++ but the community hacked the project and created levelUp, that is a levelDB handler for Node (and written in JavaScript, of course).

Now the project is more big: levelUP is high level wrapper, but also exist levelDOWN, that is the part that speak with leveldb. This design allow you use other adapters as database. In definetely to use levelDB use level and level-browserify in the browser that have the last levelUP and levelDOWN stable version.

For me, the the jewel in the crown is levelgraph, that use levelDB as Graph Database.

For know more the level project I recommend read this series of post in DailyJS written by the author of some level repositories, @rvagg.

About this , Rocksdb is the Facebook version built using LevelDB and exists a fork called level-rocksdb for use it.

Alternatively another key value database in momoery is LokiJS.

Kiko Beats

Kiko Beats