This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var primaryColors = [ | |
{color: 'red'}, | |
{color: 'yellow'}, | |
{color: 'blue'} | |
]; | |
// What we want to end up with: | |
// ["red", "yellow", "blue"] | |
// sometimes the first argument is call the accumulator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var numbers = [10, 20, 30]; | |
var sum = 0; | |
for (var i = 0; i < numbers.length; i++){ | |
sum += numbers[i]; | |
} | |
console.log("For loop way: ",sum); | |
// Results are: "For loop way: " | |
// 60 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//events - a super-basic Javascript (publish subscribe) pattern | |
var events = { | |
events: {}, | |
on: function (eventName, fn) { | |
this.events[eventName] = this.events[eventName] || []; | |
this.events[eventName].push(fn); | |
}, | |
off: function(eventName, fn) { | |
if (this.events[eventName]) { |
One of the major problems with JavaScript is the absence of namespacing. Programs that run in the global scope polluting it with data that comes from both internal application code and dependencies. A popular technique to solve this problem is called the revealing module pattern, and it looks like the following:
const module = (() => {
const privateFoo = () => {...};
query FirstNOrgMembers($login: String!, $n: Int!) {
organization(login: $login) {
id
name
members(first: $n) {
edges {
node {
id
name
Getting started:
Related tutorials:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sayAge = function() { | |
console.log(this.age); | |
} | |
var me = { | |
age: 42 | |
} | |
sayAge(); | |
window.age = 42; | |
sayAge(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Animal = function(color, name, type) { | |
this.color = color; | |
this.name = name; | |
this.type = type; | |
} | |
var zebra = new Animal('black and white', 'Zorro', 'Zebra'); | |
// When the "new" keyword is invoked a new object is created and saved as "this" |