Created
July 21, 2017 12:43
-
-
Save uniquename/a2859274df02fc2165b7655524ac882c to your computer and use it in GitHub Desktop.
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
/** | |
* Booleans | |
* | |
* Can eather be true or false | |
*/ | |
var myBoolean = true; | |
/** | |
* Numbers | |
* | |
* Positive and negative numbers. | |
* Decimal numbers are called floats. | |
*/ | |
var myNumber = 5; | |
/** | |
* Strings | |
* | |
* Any characters surounded by double quotes " " or or single quotes ' '. | |
* Remember escaping with a backslash | |
*/ | |
var myString = 'Hello World!'; | |
/** | |
* Arrays | |
* | |
* Can hold multiple values of any kind. | |
* Square brakets [] indicate an array. | |
*/ | |
var myArray = [1, 2, 4, 6, 'and', 'strings']; | |
// Can be multidimensional | |
// var myArray = [['some', 'strings'] [7, 8, 9]]; | |
// var myArray = [1, 2, true, 'some string', [7, 8, 'string']]; | |
// The key always starts with 0 | |
// console.log(myArray[0]); | |
// console.log(myArray[3][2]); | |
/** | |
* Objects | |
* | |
* Like an array but the keys are strings and their values are called propperties. | |
* | |
* Curly braces {} indicate an object. | |
* | |
* They can also have methods. See objects.js for that. | |
*/ | |
var myObject = { | |
someKey: 'some string', | |
anotherKey: ['i', 'am', 'an', 'array'], | |
} | |
// adressing a propperty | |
// console.log(myObject.someKey); | |
// console.log(myObject.anotherKey[3]); | |
var product1 = { | |
id: 234, | |
title: 'Tasty Cookies', | |
price: 1.99 | |
} | |
var product2 = { | |
id: 456, | |
title: 'Apples', | |
price: 2.99 | |
} | |
var shoppingCart = [product1, product2]; | |
console.log(shoppingCart); | |
/** | |
* Keep in mind, Objects can contain arrays of objects (...of arrays of objects...) | |
* | |
* Syntax would look like { [{}, {}], [{}, {}] } | |
*/ | |
var blogEntry = { | |
id: 654321, | |
date: '04.09.2017', | |
author: { | |
id: 12, | |
name: 'John', | |
lastname: 'Doe' | |
}, | |
title: 'Hey, some great News!', | |
body: 'Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum.', | |
comments: [{ | |
id: 55675, | |
title: 'hey there', | |
body: 'that where really great news!' | |
}, { | |
id: 55676, | |
title: 'oh really?!', | |
body: 'thats nice to hear!!!' | |
}] | |
} | |
//console.log(blogEntry); | |
/* | |
console.log(myBoolean); | |
console.log(typeof myBoolean); | |
console.log(myNumber); | |
console.log(typeof myNumber); | |
console.log(myString); | |
console.log(typeof myString); | |
console.log(myArray); | |
console.log(typeof myArray); | |
console.log(myObject); | |
console.log(typeof myObject); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment