JS (ES5, ES6, ES7)

Wednesday, January 11, 2017

javascript in client, server, database, node_modules, addons, cloud

Open Source Rules!

future technologies (the open source world is yours):


attitude, facts and mission ...

we are fearless, ruthless and honest, the goal is progress. we are constantly focused on our goal, produce quality working software as fast as possible. we are open source.


Proper Tail Calls

                    
//proper tail calls
"use strict";
function foo(num){
    try {
        return foo((num || 0) + 1);
    } catch(e) { return num;}
}
console.log(foo()); //15714

function fibonacci(x, y, limit, index){
    if (arguments.length === 1){
        if (x){
            return fibonacci(0, 1, x, 1);
        }
        return 0;
    } else {
        if (index < limit){
            return fibonacci(y, (x + y), limit, ++index);
        }
        return y;
    }
}

console.log(fibonacci(3)); //2
console.log(fibonacci(10)); //5
console.log(fibonacci(13123)); //RangeError BIG BLOODY NUMBER
                        
                    

Variable Hoisting

                    
"use strict";

//variable hoisting
function outer() {
    a = 0; //reference error a is not hoisted
    inner();
function inner() {
    b = 2;
}
}
outer();
var foo = 2;
if (true){
    var bar = 1;
}
console.log(foo + bar); //3

console.log(name); //undefined
var name = "Marc";

//function declaration
function foo(){

}

//function expression
var bar = function() {

}
                        
                    

Basics refresher

                    
//querySelector returns first element within document that matches specified group of selectors
        var myHeading = document.querySelector('h1');
        myHeading.textContent = 'hello world';
'use strict';
//variables are containers to store values in
var myVariable = 'hello world'; //string
var myVariable1 = 10; //number
var myVariable2 = true; //boolean
var myVariable3 = [1, 'bob', 'steve', 10]; //array
var myVariable4 = {}; //object
//add concatenation
var a = 6 + 9;
var b = "hello " + "world!";
//subtract multiply divide
var c = 9 - 3;
var d = 8 * 2;
var e = 9 / 3;
//assign a value to a variable =
var f = 'push it, baby push it.';
//identity operator, tests to see if two values are equal returns true or false ===
var g = a === 15;
//negation operator !
var h = b !== b;
//conditionals if else
var iceCream = 'chocolate';
if (iceCream === 'chocolate'){
  console.log(iceCream +  ' is selected');
} else {
  console.log(iceCream +  ' is not selected');
}
//functions package functionality to reuse
function multiply(num1, num2){
  var result = num1 * num2;
  return result;
}
console.log(multiply(0.5, 3));

                        
                    

onclick, localStorage, querySelector, getAttribute, setAttribute


                    

                        
                    

                    

                        
                    

                    

                        
                    

                    

                        
                    

                    
                        
                    

                    
                        
                    

                    

                        
                    

                    

                        
                    

Default Success Warning Important Info Inverse
B S W I ? O