Skip to content

Instantly share code, notes, and snippets.

@0bie
0bie / value-reference.js
Created September 12, 2017 23:23
Understanding JS value and reference
// JS has 5 data types that are assigned by value:
// `Boolean`, `String`, `Number`, `null`, `undefined` (primitives)
// JS has 3 data types that are assigned by reference:
// `Array`, `Function`, `Object` (objects)
var x = 1, y = '1', z = undefined;
// When we assign these vars to other vars we copy the value to the new var
var a = x, b = y, c = z;
@0bie
0bie / modules.js
Last active September 27, 2017 05:26
JS Module Patterns
// Anonymous function:
// Ex.1
(function() {
// We keep these variables private inside this closure scope
var myGrades = [93, 95, 88, 0, 55, 91];
var average = function() {
var total = myGrades.reduce(function(accumulator, item) {
return accumulator + item;
}, 0);
return 'Your average grade is ' + total / myGrades.length + '.';
@0bie
0bie / objectCreation.js
Last active October 20, 2017 09:30
Creating objects in JavaScript
// `bind` and `this`
let dog = {
sound: 'woof',
talk: function() {
console.log(this.sound);
}
}
dog.talk(); // => 'woof'
@0bie
0bie / boolean.js
Last active November 8, 2017 19:21
Convert values to boolean in JS
// In JS `!!` can be used to convert any value to a boolean
// Similar to using the Boolean() function
(function() {
var foo = 'foo';
console.log(typeof foo);
var bool = !!foo;
console.log(typeof bool);
console.log(bool);
@0bie
0bie / sqlNotes.md
Created December 29, 2017 23:16
Learning SQL

SQL

Log into database: mysql [db_name]

View a table: SELECT * FROM table_name;

Update a record in a table:

UPDATE [table_name] SET [table_column] = NOW() WHERE id = 1;

@0bie
0bie / deepCopy.js
Last active September 21, 2022 17:19
/**
* check if vals are objects
* if so. copy that object (deep copy)
* else return the value
*/
function deepCopy(obj) {
const keys = Object.keys(obj);
const newObject = {};
for (let i = 0; i < keys.length; i++) {