Skip to content

Instantly share code, notes, and snippets.

View jtulk's full-sized avatar

Justin Tulk jtulk

  • El Paso, Texas
View GitHub Profile
@jtulk
jtulk / sample.js
Last active August 29, 2015 14:27
Example #4: Understanding Function Hoisting in Javascript
// Example 4.1: Function Hoisting
function subFunction(){
return 'foo';
}
console.log(subFunction());
function subFunction(){
return 'baz';
@jtulk
jtulk / sample.js
Created August 10, 2015 23:15
Example 4: Function Hoisting
// Example 4.2: Function Hoisting
function comboFunction(){
function subFunction(){
console.log('foo');
}
return subFunction();
function subFunction(){
console.log('baz');
}
@jtulk
jtulk / sample.js
Created August 10, 2015 23:59
Example 4: Function Hoisting Explained
// Example 4.1:
function subFunction(){
console.log('foo');
}
console.log(subFunction());
function subFunction(){
console.log('baz');
}
@jtulk
jtulk / sample.js
Last active August 29, 2015 14:27
Example 5: Function Hoisting
// Adding variable assignments to Example 4.1
// to create function expressions
var x = function (){
return 'foo';
}
console.log(x());
x = function (){
return 'baz';
@jtulk
jtulk / main.js
Created September 22, 2015 03:26
Javascript Configuration and Events for Slick Slider Bug
// Configure the list animations on single project views
var galleries = $('.carousel-gallery');
var carousels = $('.carousel');
$.each(galleries, function(){
var that = $(this);
var subGalleries = that.find('li');
var numSubGalleries = subGalleries.length;
that.attr('data-index', numSubGalleries);
})
@jtulk
jtulk / script.js
Created September 29, 2015 05:36
Ternary Operator Sample
var foo,
a = 1,
b = 2;
foo = a === b ? 'Matches' : 'Does not match';
console.log(foo); // 'Does not match'
@jtulk
jtulk / script.js
Created September 29, 2015 06:10
Testing for a DOM Element
var $myCarousel = $('#myCarousel');
if($myCarousel){
console.log('Carousel Exists');
} else {
console.log('Carousel Does Not Exist Yet');
}
// 'Carousel Exists'
@jtulk
jtulk / script.js
Created September 29, 2015 06:20
Testing for a DOM Element without jQuery
var myCarousel = document.getElementById('myCarousel');
if(myCarousel) {
console.log('Carousel Exists');
} else {
console.log('Carousel Does Not Exist');
}
// 'Carousel Does Not Exist'
@jtulk
jtulk / projectReducer.js
Last active May 20, 2016 21:16
A demo reducer for Redux
const ADD_PROJECTS = "projects/add_projects"
const initialState = {
projects: []
}
export default function reducer(state = initialState, action = {}){
switch(action.type){
case ADD_PROJECTS:
return {
@jtulk
jtulk / projectReducer.js
Last active December 20, 2022 07:55
Merge, Dedupe, and Update Arrays in a Redux Reducer
const ADD_PROJECTS = "projects/add_projects"
const initialState = {
projects: []
}
function reducer(state = initialState, action = {}){
switch(action.type){
case ADD_PROJECTS: