Javascript can be dynamically typed – Array Example

This is code example of javascript being dynamically typed with arrays. Arrays can store, anything: strings, objects, functions, strings, and integers. Below is example how to call an object lateral and function. Remember arrays start count at 0.

var arr = [1,
           name: 'jason',
             addy: '111 fake st'
           	var greeting = 'hello ';
             console.log(greeting + name);

// hello jason

How to Setup Babel es2015 Javascript on Windows 8.1?

First create a folder:
Then CD into that folder through CMD
Then do the follow in command-line

npm init
npm install -g babel-cli
npm install babel-preset-es2015–save-dev

Then create app.js.es6 file

Then use this example code:

class Person {
	constructor(name) { = name;
		return "Hello I am ${}";

let person = new Person("Tyler");

babel app.js.es6 –presets2015 | clip

Clip copies the string from commandline. Then you should get the follow code output:

"use strict";

var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Person = (function () {
	function Person(name) {
		_classCallCheck(this, Person); = name;

	_createClass(Person, [{
		key: "greet",
		value: function greet() {
			return "Hello I am ${}";

	return Person;

var person = new Person("Tyler");

Now we want to create an index.html file

<!DOCTYPE html>
<html lang="en">
	<meta charset="UTF-8">

	<script src="app.js"></script>

babel app.js.es6 –presets es2015 > 5

Now we are going to create a file called .bablrc this file will shorten the command to compile the babel file

	presets: ["es2015"]

Next we type in this code to make compiling es2015 javascript faster.

babel app.js.es6 > app.js


javascript – namespacing, public and private data

This is quick code sample of public and private data using javascript. You would create anonymous call back function. Private data would be store in var.
Public data would be returned.

// we create anonymous callback function to create private and public functions
var THINGS = function() {
// private
var gifts = 3;
// public
return {
    gems: 1000,
    gold: 2000,
    swords: 300,
    SECRET: {
      open: function() {

I hope you found this code snippet useful in your coding. These are higher order examples of code has to deal with object orientated programming. You can apply these concepts elsewhere.

Public functions can be access and changed anywhere. Where as private can’t be changed the numbers stay static. For example gifts will stay 3, but the public function can subtract it in increments of negative 1.

The reason behind public and private is track bugs. If you have too many public/global variables you get lost quick and other variables can overwrite those current variables, which is something you don’t want. Plus there is name spacing here the namespace is THINGS.

Javascript – Sales Tax Program

function tax (price, percent) {
		return parseFloat((price*percent/100).toFixed(2));
	var randomItem = 9.85;
	var salesTax = 7.5;
	var total = randomItem + tax(randomItem, salesTax);


This is a program on how to calculate sales tax with javascript, because handling floats is a bit weird with javascript.

How to Benchmark Your Javascript?

This is a quick tutorial on how to benchmark your javascript with console.time(“arg”) and console.timeEnd(“arg”)
You would use developer tools to see how fast your script runs.

Example Code:

Array.prototype.proto1 = function(){};
Array.prototype.proto2 = function(){};
Array.prototype.proto3 = function(){};
Array.prototype.proto4 = function(){};
Array.prototype.proto5 = function(){};

var objectLateral = {
  arrayBank: ['Some random string', 'Other String', 'More Stringy Spaghetti']

function runThisCode(){
  var things = objectLateral.arrayBank,
      list = "";

  for(var i = 0, ff = things.length; i < ff; i++){
    list += (things[i] + " ");

  return list.trim();


Returning Functions and Immediate Invocation

// ride and wait time
var parkRides = [["birch bumpers", 40], ["dank bumpers", 36], ["trap bumpers", 41], ["wtf bumpers", 43],];
// fast pass for faster line
var fastPassQueue = ["birch bumpers", "dank bumpers", "trap bumpers", "wtf bumpers"];
// allRides arg - this parameter will be the array of the rides and their wait time
// passrides arg - this will be the array of the nxt available fast pass rides
// pick arg - this will be the actual ride for which our customer would like a ticket!
function buildTicket(allRides, passRides, pick) {
	if(passRides[0] == pick){
		var pass = passRides.shift();
		return function() {alert("Quick! You've got a fast pass to " + pass +"!"); 
	} else {
		for(var i =0; i<allRides.length;i++){
				return function () {alert("A ticket is print for " + pick +"!\n" + "Your wait time is about " + allRides[i][1] + " minutes.");
var wantsRide = "birch bumpers";
// self invoking function when you add () at the end off the function
buildTicket(parkRides, fastPassQueue, wantsRide)();


This is hypothetical fast pass system created with functions, arrays, conditional, and for loop statement. All written javascript.

Reserved Characters in URLs – PHP

These are list of following of reserved characters for links:

! # $ % & ( ) * + , / : ; = ? @ [ ]

These characters need to be encoded so it doesn’t interfere with the function of the URL.

These characters will turn into %21 hexadecimal characters.

A fix for this is





  • Letters, numbers, underscores, and dash are unchanged
  • Reserved characters become % + 2 digit hexadecimal
  • Spaces become “+”
  • Use this for query string after that ?


  • rawurlencode should only be used for file path
  • path is the part before “?”
  • spaces must be %20
  • it’s newer

Javascript – Magic 8 Ball Script

This is a magic 8 ball program written in html and javascript. So it’s very lean fast and quick. You are free to use this script because it’s open source I made this solely for fun. So fork it. This is basically a random answer generator which uses random number and switch statement to be written. Have fun. 😉

<!DOCTYPE html>
<html lang="en">
	<meta charset="UTF-8">
	<title>Magic 8 ball</title>
	<input type="text" placeholder="Ask your question?">
	<button onclick="myFunction()">Answer</button>
	<p id="demo"></p>

function myFunction() {
	function getRandomArbitrary(min, max) {
	return Math.floor(Math.random() * (max - min) + min);
	var num = getRandomArbitrary(1,6);

	switch(num) {
	    case 1:
	        answer = "Yes";
	    case 2:
	        answer = "No";
	    case 3:
	        answer = "Try Again";
	    case 4:
	        answer = "Outlook not so good";
	    case 5:
	        answer = "Most definitely!";
	document.getElementById("demo").innerHTML = answer;


Magic 8 Ball Demo

jQuery – $.each vs $.map jquery

We are going to go over what are the difference between $.each and $.map in jquery. Both are like foreach loops, but utilized differently.

The each method is meant to be an immutable iterator, where as the map method can be used as an iterator, but is really meant to manipulate the supplied array and return a new array.

Another important thing to note is that the each function returns the original array while the mapfunction returns a new array. If you overuse the return value of the map function you can potentially waste a lot of memory.

    var cities = ['Paris', 'London', 'Orlando'];
    $.each(cities, function(index, city){
        var result = city + " " + index;
    // paris 0
    // london 1
    // orlando 2

    $.map(cities, function(city, index){
        var result = city + " " + index;
        return result;
    // paris 0
    // london 1
    // orlando 2