GithubHelp home page GithubHelp logo

week2_monday's Introduction

#Outline for Monday 9/21

  • Review Wednesday's Exercise
  • Objects

##Review Wednesday's Material

Objects

The DOCS

Similar to an Array, an Object is a set of key/value pairs, with each key having to be unique. Variables inside an object are known as properties, while functions are known as 'methods'. The value of a property can be a string, number, boolean, array or another object. The value of a method is always a function.

This might sound confusing.

You might be thinking "nope."

But it will all make sense once you get started!

##Let's model an Object!! Group modeling of object.

###Creating an Object using Literal Notation

var hotel = {
  name: 'Hilton',
  rooms: 120,
  booked: 93,
  pool: true,
  roomTypes: ['twin', 'full', 'queen', 'king'],
  //we will cover functions in greater depth next week
  availability: function() {
    return this.rooms - this.booked;
  }
};

###Creating an Object using Constructor Notation

var hotel = new Object();
//properties
hotel.name = 'Best Western';
hotel.rooms = 65;
hotel.booked = 34;
//method
hotel.availability = function() {
  return this.rooms - this.booked;
};

###Accessing an Object The properties and methods of an object can be accessed using dot notation. Properties can also be accessed using square brackets.

var hotelName = hotel.name;
// Hilton
var availableRooms = hotel.availability;
// 27
var hotelName = hotel['name'];
// Hilton

###Updating and adding to an Object To add to or update the properties of an object, dot notation or square brackets can be used.

hotel.pool = false; //sets the pool property to false

hotel.lounge = true; //adds a new lounge property with a value of true

hotel;
// {name: 'Hilton', rooms: 120, booked: 93, pool: false, lounge: true, availability: function(){....};}

###Deleting a property Use the 'delete' keyword followed by the object and property names. To clear the value of a property without deleting it, set its value to a blank string ''

delete hotel.pool; //deletes the pool property from the hotel object

hotel.name = ''; //clears the value

##In Class Exercise Creating and manipulating objects.

week2_monday's People

Contributors

calebatwood avatar jennyallar avatar andogro avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.