On Github mauricio / javascript-from-hell
var jose = {"nome":"José"}; var maria = {"nome":"José"}; jose == maria > false jose.nome == maria.nome > true 1 == "1" > true 1 == 1 > true 1 === "1" > false 1 === 1 > true
function Person(name) { this.name = name; } Person.prototype.hello = function() { return "Hello " + this.name; } var me = new Person("Joe"); me.hello() > "Hello Joe" var other = Person("Mark"); other.hello() > TypeError: Cannot call method 'hello' of undefined
function Person(name) { if ( !(this instanceof Person) ) return new Person(name); this.name = name; } Person.prototype.hello = function() { return "Hello " + this.name; } var other = Person("Mark"); other.hello() > "Hello Mark"
name = "Mario"; var otherName = "Luigi"; (function updateName(){ var otherName = "Yoshi"; name = "Bowser"; var princess = "Peach"; drunk = "Toad"; }()); console.log(name); > Bowser console.log(drunk); > Toad console.log(otherName); > Luigi console.log(princess); > ReferenceError: princess is not defined
var obj = {"name":"Rex Colt"}; with(obj) { surname = name.split(" ")[1]; } console.log(obj["surname"]); > undefined console.log(surname); > Colt
[] + [] > "" [] + {} > [object Object] {} + [] > 0 {} + {} > NaN
[] + [] > [] [] + {} > TypeError: no implicit conversion of Hash into Array {} + [] > NoMethodError: undefined method `+' for {}:Hash
function myAction(result) { console.log("result is " + result); } client.connect(function(err) { if(err) { return console.error('could not connect to postgres', err); } client.query("BEGIN TRANSACTION", function(err, result) { if(err) { return console.error('error running query', err); } client.query("SELECT 0", function(err, result) { if(err) { return console.error('error running query', err); } client.query("COMMIT", function(err, result) { if(err) { return console.error('error running query', err); } myAction(result); }); }); });
val handler = new DatabaseConnectionHandler( ... ) val result = handler.connect .map( parameters => handler ) .flatMap( connection => connection.sendQuery("BEGIN TRANSACTION") ) .flatMap( query => handler.sendQuery("SELECT 0") ) .flatMap( query => handler.sendQuery("COMMIT") .map( value => query.rows(0) ) )
var items = [1, 2, 3]; for ( var x = 0; x < items.length; x++ ) { var item = items[x]; } console.log(item); > 3
var items = [1, 2, 3]; items.forEach( function(item) { console.log("item é " + item); } ); console.log(item); > ReferenceError: item is not defined
myFunction(); function myFunction() { console.log("function called"); } var myFunction = function () { console.log("variable called"); } > "function called"
function myFunction() { console.log("function called"); } var myFunction = function () { console.log("variable called"); } myFunction(); > "variable called"
( function myFunction() { console.log("function called"); } ); myFunction(); > ReferenceError: myFunction is not defined