Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Variables
- _const_ - Constant, can't be changed
- ``` javascript
- const tickets = 3;
- // tickets === 3
- ```
- _let_ - Temporary, can be changed
- ``` javascript
- let tickets = 3;
- let tickets = tickets - 1; // somebody purchases a ticket
- // tickets === 2
- ```
- # Primitives
- _boolean_ - true / false
- ``` javascript
- const hasRemainingTickets = true;
- // if we have tickets remaining
- if (hasRemainingTickets === true) {
- purchaseTickets(1); // purchase 1 ticket
- }
- ```
- _number_ - any number positive or negative
- ``` javascript
- // whole numbers
- const positiveNumber = 13;
- const negativeNumber = -42;
- // float numbers
- const floatNumber = 4.43;
- const negativeFloatNumber = -9.75;
- ```
- _string_ - any combination of characters or number
- ``` javascript
- // characters only
- const firstName = 'Lance';
- const fullName = 'Lance Jernigan';
- // characters and numbers
- const username = 'Pineapple17';
- const password = 'Y21@EUVK9Ur1H!';
- ```
- _null_ - intentionally empty
- ``` javascript
- const paddleBoats = null;
- // We don't sale paddleBoats but we could
- ```
- _undefined_ - exists but doesn't have a value
- ``` javascript
- let tickets;
- if (tickets === undefined) {
- let tickets = 0;
- // we should make sure there's a numerical value
- }
- ```
- # Objects
- _object_ - represents a data structure
- ``` javascript
- const user = {
- firstName: 'Lance',
- lastName: 'Jernigan',
- phone: '8653041322',
- email: 'lance.t.jernigan@gmail.com',
- userId: 3,
- }
- ```
- _array_ - a list of items
- ``` javascript
- // numbers
- const primesLessThan10 = [ 1, 3, 5, 7 ];
- // strings
- const shows = [
- 'Fantastic Beasts: The Crimes of Grindelwald',
- 'Bohemian Rhapsody',
- 'The Grinch',
- ];
- //objects
- const tickets = [
- {
- type: 'adult',
- price: 12.35,
- },
- {
- type: 'child',
- price: 9.75,
- }
- ]
- ```
- _function_ - an action
- ``` javascript
- let tickets = 3;
- const purchaseOneTicket = () => {
- let tickets = tickets - 1; // subtract 1 from tickets
- }
- purchaseOneTicket();
- ```
- Functions can return any value
- ``` javascript
- const subtract = (a, b) => {
- // a = 3
- // b = 1
- return a - b; // 3 - 1 = 2
- }
- const tickets = subtract(3, 1);
- // tickets === 2;
- ```
Add Comment
Please, Sign In to add comment