Level 36
Level 38
96 words 0 ignored
Ready to learn
Ready to review
Ignore words
Check the boxes below to ignore/unignore words, then click save at the bottom. Ignored words will never appear in any learning session.
Ignore?
What does this loop resemble in php?
for each loop that we use for arrays
how many times will the loop executed for each property?
The block of code inside of the for...in loop will be executed once for each property.
how do we loop through an object?
var person = {fname:"John", lname:"Doe", age:25};
How can we add new properties to an existing object?
You can add new properties to an existing object by simply giving it a value.
syntax for that
Assume that the person object already exists - you can then give it new properties:
Can we use special words for property names?
You cannot use reserved words for property (or method) names. JavaScript naming rules apply.
What does the delete keyword delete?
The delete keyword deletes both the value of the property and the property itself.
When can the deleted property used again after it was deleted?
After deletion, the property cannot be used before it is added back again.
Can the delete operator be used on variables and functions?
The delete operator is designed to be used on object properties. It has no effect on variables or functions.
Can the delete operator be used on predefined object properties?
The delete operator should not be used on predefined JavaScript object properties. It can crash your application.
What do all property have?
All properties have a name. In addition they also have a value.
What is the name to a property?
The value is one of the property's attributes. it is the name value attribute
What other attributes does a property have?
Other attributes are: enumerable, configurable, and writable.
What do enumerable, congifurable and writable define attributes do?
These attributes define how the property can be accessed (is it readable?, is it writable?)
Which values can be read and which ones can be changed?
In JavaScript, all attributes can be read, but only the value attribute can be changed (and only if the property is writable).
When can the value attribute changed?
only if the property is writable
yes
Can functions be used in expressions?
how many methods are there for that?
( ECMAScript 5 has methods for both getting and setting all property attributes)
What about the properties of prototypes?
JavaScript objects inherit the properties of their prototype.
What if we delete a prototype property with delete keyword?
The delete keyword does not delete inherited properties, but if you delete a prototype property, it will affect all objects inherited from the prototype.
What is an object in js?
In JavaScript, almost "everything" is an object.
Booleans can be objects (or primitive data treated as objects)
What are objects and what are primitive data treated as objects?
What are not objects in js?
In JavaScript, all values, except primitive values, are objects.
What are primitive values?
Primitive values are: strings ("John Doe"),
single values
What do variables contain?
var person = "John Doe";
declaring a variable with a single value
How are the values written in objects (and arrays)?
The values are written as name : value pairs (name and value separated by a colon).
declaring an object
var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
What are ojbects?
A JavaScript object is an unordered collection of variables called named values.
What are the named values called?
The named values, in JavaScript objects, are called properties.
What are js objects similar to?
Objects written as name value pairs are similar to:
What are methods?
Methods are actions that can be performed on objects.
What kind of values can an object property be?
Object properties can be both primitive values, other objects, and functions.
What is an object method?
An object method is an object property containing a function definition.
What are js objects?
JavaScript objects are containers for named values, called properties and methods.
Can you create and define your own object in js?
With JavaScript, you can define and create your own objects.
How many ways can you create an object?
1.Define and create a single object, using an object literal.
Why is object literal is the easiest way to create a js object?
Using an object literal, you both define and create an object in one statement.
What is the object literal made up of?
An object literal is a list of name:value pairs (like age:50) inside curly braces {}.
do space and breaks matter?
Spaces and line breaks are not important. An object definition can span multiple lines:
they do not matter
var person = {
is there any difference between the object literal and keyword new?
The two examples above do exactly the same. There is no need to use new Object().
What is the better of the 2?
For simplicity, readability and execution speed, use the first one (the object literal method).
What is the drawback of object literal and keyword new?
The examples above are limited in many situations. They only create a single object.
Why is object construction better?
Sometimes we like to have an "object type" that can be used to create many objects of one type.
What is the advantage of the object constructor?
The above function (person) is an object constructor.
var myFather = new person("John", "Doe", 50, "blue");
What is the syntax of making many objects from an object constructor?
What is this?
In JavaScript, the thing called this, is the object that "owns" the JavaScript code.
What is this when used in a function?
The value of this, when used in a function, is the object that "owns" the function.
What is this when used in an object?
The value of this, when used in an object, is the object itself.
What is the value of this in an object constructor?
The this keyword in an object constructor does not have a value. It is only a substitute for the new object.
can this be changed?
Note that this is not a variable. It is a keyword. You cannot change the value of this.
Do js have built-in constructors?
JavaScript has built-in constructors for native objects:
Why is the Math object is not in the list?
The Math() object is not in the list. Math is a global object. The new keyword cannot be used on Math.
What is mutable?
liable to change: the mutable nature of fashion.
What does it mean that objects are mutable?
Object are mutable: They are addressed by reference, not by value.
What do we mean by reference?
If y is an object, the following statement will not create a copy of y:
var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"}
Any changes to y will also change x, because x and y are the same object.
In what kind of container is a js method?
A JavaScript method is a property containing a function definition.
methodName : function() { code lines }
What is the syntax of creating an object method (in an object literal)?
objectName.methodName ()
syntax for calling a method of an object
How would you describe fullName()?
You will typically describe fullName() as a method of the person object, and fullName as a property.
name = person.fullName();
This example accesses the fullName() method of a person object:
it will return the function definition:
What will happen If you access the fullName property, without (),
var x = message.toUpperCase();
This example uses the toUpperCase() method of the String object, to convert a text to uppercase:
How can can we define a method to an object?
Defining methods to an object is done inside the constructor function:
this.eyecolor = eyecolor;
The constructor is assigned to a variable and that way we create an object.
myMother.changeName("Doe");
The changeName() function assigns the value of name (variable ) to the person's lastname property.
How can js identify which person we are talking about?
JavaScript knows which person you are talking about by "substituting" this with myMother which is the name of the instance of the object.
What datatype are properties?
Datatype properties are strings
Are objects immutable or mutable?
Objects are mutable, which means if a variable refers to an object, the variable holds a reference to the direct object, it does not make a copy of the object.
Can properties have the same name?
No, otherwise there would be no way to reference each individual key-value pair.
What are the three object property attributes and what do they do?
writable Attribute specifies whether the value of A property can be set
What are the three associated object attributes?
Prototype: a reference to another object from which properties are inherited
What are native objects?
Object or class of objects defined my EMCAscript such as functions, arrays, dates and regular expressions
What is a host object?
An object that is defined by the host environment (such as a web browser)
What is a user-defined object?
object created by the user
What is an own property?
property defined directly on an object
What is an inherited property?
A property defined by an object's prototype object.
What is a prototype?
A second object associated with each JavaScript object and whose properties are inherited by it
What prototype do literal objects use? How is this different than the constructor and create objects?
Object literal = Object.prototype() Constructor = prototype property of their constructor function Object.create = first argument
What prototype does object.prototype inherit?
It doesn't inherit any properties. Rather, all build-in constructors inherit properties from it.
What is prototype chaining?
Each object has an internal link to another object called its prototype. That prototype object has a prototype of its own, and so on until an object is reached with null as its prototype. n…
Use the dot or bracket notation
How do you query a property of an object?
What is the advantage of using bracket notation over dot notation to access a property of an object?
When you access a property of an object with the [] notation, the name of the property is expressed as a string. Since strings are a JS datatype, they can be manipulated and created while the program is running.
Undefined.
If you query a property that does not exist what is returned?
Why are you not always able to set property values in an object?
The properties may be read-only, an inherited property is read-only, or set so they cannot have any additional properties.
use the delete operator; this will not delete inherited properties.It operates on the property, not the value.
How do you delete a property? Does this delete inherited properties as well? Does the delete property operate on the value or the property?
When will the delete expression evaluate to true?
When the delete succeeded or if the delete had no effect.
How can you test the properties of an object? Which methods return true/false for inherited properties?
The in operator: takes a property name on its left side and an object on its right side. It returns true if an object has an own or inherited property by that name.
Use a for/in loop.
How do you iterate through an entire object's properties?
What are two other ways to enumerate property names?
object.keys() which returns an array of the names of enumerable own properties of an object.
???
Define getter and setters
object.getPrototypeOf();
How do you query the prototype of an object?
What is an object's class?
A class is a string that provides information about the type of an object?
Invoke the toString() method;
How do you obtain the class of an object?