Functions, Methods, & Objects Flashcards

1
Q

Method vs. Function

A

A method is on an object.
A function is independent of an object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Calling the Function

A

Asking the function to perform its task

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Parameters

A

Pieces of information passed to a function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Return Value

A

An answer you expect a function to provide

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Arguments

A

When you call a function that has parameters, you specify the values it should use in the parentheses that follow its name. The values are called arguments, and they can be provided as values or as variables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Parameters vs. Arguments

A

Parameters

function getArea(width, height) {

return width * height;

}

When the function is declared, you can see the words width and height used. Inside the curly braces of the function, those words act like variables.

Arguments

wallWidth = 3;

wallHeight = 3;

getArea(wallWidth, wallHeight);

You can see that the getArea() function is being called and the code specifies real numbers that will be used to perform the calculation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Function Declaration

A

A function declaration creates a function that you can call later in your code. In order to call the function later in your code, you must give it a name, so these are known as named functions.

function area(width, height) {

return width * height;

};

var size = area(3, 4);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Function Expression

A

If you put a function where the interpreter would expect to see an expression, then it is treated as an expression, and it is known as a function expression. In function expressions, the name is usually omitted. A function with no name is called an anonymous function.

var area = function(width, height) {

return width * height;

};

var size = area(3, 4)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Local Scope

A

When a variable is created inside a function using the var keyword, it can only be used in that function. Below, area is a local variable.

function get(width, height) {

var area = width * height;

return area;

}

var wallSize = getArea(3, 2);

document.write(wallSize);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Global Scope

A

If you create a variable outside of a function, then it can be used anywhere within the script. It is called a global variable and has global scope. In the example shown, wallSize is a global variable.

function get(width, height) {

var area = width * height;

return area;

}

var wallSize = getArea(3, 2);

document.write(wallSize);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Objects, Properties, & Methods

A

Objects group together a set of variables and functions to create a model of a something you would recognize from the real world. In an object, variables and functions take on new names.

If a variable is part of an object, it is called a property. Properties tell us about the object, such as the name of a hotel or the number of rooms it has.

If a function is part of an object, it is called a method. Methods represent tasks that are associated with the object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Key

A

Like variables and named functions, properties and methods have a name and a value. In an object, that name is called a key.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Literal Notation

A

var hotel = {

name: “Quay”,
rooms: 40.
booked: 25,

checkAvailability: function() {

return this.rooms - this.booked;

}

};

Object = hotel

Properties = name, rooms, booked…& values

Method = checkAvailability…& values

Key = name, rooms, booked, checkAvailability

Value = “Quay”, 40…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Constructor Notation

A

The new keyword and the object constructor create a blank object. You can then add properties and methods to the object.

var hotel = new Object();

hotel. name = “Quay”;
hotel. rooms = 40;
hotel. booked = 25;
hotel. checkAvailability = function () {

return this. rooms - this.booked;

};

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Dot Notation

A

var hotelName = hotel.name;

var roomsFree = hotel.checkAvailability();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

this

A

The keyword this is commonly used inside functions and objects. Where the function is declared alters what this means. It always refers to one object, usually the object in which the function operates.

25
Q

Browser Object Model

A

The BOM contains objects that represent the current browser window or tab. It contains objects that model things like browser history and the device’s screen.

26
Q

Document Object Model

A

The DOM uses objects to create a representation of the current page. It creates a new object for each element (and each individual section of text) within the page.

27
Q

Global JavaScript Objects

A

The global JavaScript objects represent things that the JavaScript language needs to create a model of. For example, there is an object that deals only with dates and times.

28
Q
A