Shared Flashcard Set

Details

Javascript MDN
From the javascript reference at Mozilla Developer Reference
47
Computer Science
9th Grade
02/19/2017

Additional Computer Science Flashcards

 


 

Cards

Term

What is NaN?

Definition

Not a Number.

It is the returned value when Math functions fail (Math.sqrt(-1)) or when a function trying to parse a number fails (parseInt("blabla")).

Term

What is undefined?

Definition

A variable that has not been assigned a value is of type undefined. A method or statement also returns undefined if the variable that is being evaluated does not have an assigned value. A function returns undefined if a value was not returned.

You often test vars against undefined, rather than null.

Term

What is null?

Definition

The value null represents the intentional absence of any object value. It is one of JavaScript's primitive values.

typeof null // "object" (not "null" for legacy reasons)
typeof undefined // "undefined"
null === undefined // false
null == undefined // true
null === null //true
null == null //true
!null // true
isNaN(1 + null) //false
isNaN(1 + undefined) //true

Term

eval(string)

Definition
execute the string passed in. Avoid when possible. Can be dangerous executing passed in user content.
Term

isFinite(testValue);

Definition
false if the argument is positive or negative Infinity or NaN; otherwise, true.
Term

isNaN();

Definition
The isNaN() function determines whether a value is NaN or not. Note: coercion inside the isNaN function has interesting rules; you may alternatively want to use Number.isNaN(), as defined in ECMAScript 2015, or you can use typeof to determine if the value is Not-A-Number.
Term

parseFloat(string);

Definition

A floating point number parsed from the given string. If the first character cannot be converted to a number, NaN is returned.

Term

parseInt(string, radix);

Definition

An integer number parsed from the given string. If the first character cannot be converted to a number, NaN is returned. Most implementations default to base 10. strings prefixes with 0x are evaluated as hex. strings prefixed with 0 are evaluated as octal

parseInt('12a') returns 12

Term

decodeURI(encodedURI);

Definition
encodeURI in less common, and misleadingly named: it should really be called fixBrokenURI. It takes something that's nearly a URI, but has invalid characters such as spaces in it, and turns it into a real URI
Term

decodeURIComponent(string);

Definition

encodeURIComponent()/decodeURIComponent() is for concatenating and splitting apart text strings in URI parts.

Encodes the colon and slash and plus characters, and is meant to be used in query strings. The encoding of + and ? and & is of particular importance here, as these are special chars in query strings.

Term

encodeURI(uri);

Definition

Assumes that the URI is a complete URI, so does not encode reserved characters that have special meaning in the URI.

Term

encodeURIComponent(str);

Definition
A new string representing the provided string encoded as a Uniform Resource Identifier (URI) component.
Term

escape(str);

Definition

deprecated, along with unescape().

Use encodeURIComponent() or decodeURIComponent()

Term

Object

Definition

The Object constructor creates an object wrapper.

// Object initialiser or literal { [ nameValuePair1[, nameValuePair2[, ...nameValuePairN] ] ] } 

// Called as a constructor new Object([value])
Term

Object.assign(target, ...sources)

Definition

Copy the values of all enumerable own properties from one or more source objects to a target object. It will return the target object.

Does not do deep cloning. Not supported on IE

Term

Object.create(proto[, propertiesObject)


Definition

The Object.create() method creates a new object with the specified prototype object and properties.

Term

Object.defineProperties(obj, props);

Definition
The Object.defineProperties() method defines new or modifies existing properties directly on an object, returning the object.
Term

Object.defineProperty(obj, prop, descriptor);

Definition

This method allows precise addition to or modification of a property on an object. Normal property addition through assignment creates properties which show up during property enumeration (for...in loop or Object.keys method), whose values may be changed, and which may be deleted. This method allows these extra details to be changed from their defaults. By default, values added using Object.defineProperty() are immutable.

Term

Object.freeze(obj);

Definition

Nothing can be added to or removed from the properties set of a frozen object. Any attempt to do so will fail, either silently or by throwing a TypeError exception (most commonly, but not exclusively, when in strict mode).

Values cannot be changed for data properties. Accessor properties (getters and setters) work the same (and still give the illusion that you are changing the value). Note that values that are objects can still be modified, unless they are also frozen.

Term

Object.getOwnPropertyDescriptor(obj, prop);

Object.getOwnPropertyDescriptors(obj);

Definition

The Object.getOwnPropertyDescriptor() method returns a property descriptor for an own property (that is, one directly present on an object and not in the object's prototype chain) of a given object.

d = Object.getOwnPropertyDescriptor(o, 'bar');
// d is { configurable: true, enumerable: true, value: 42, writable: true }
Term


Object.getOwnPropertyNames(obj)

Definition
returns an array whose elements are strings corresponding to the enumerable and non-enumerable properties found directly upon obj.
Term

Object.getOwnPropertySymbols()

Definition
Similar to Object.getOwnPropertyNames(), you can get all symbol properties of a given object as an array of symbols.
Term

Object.getPrototypeOf(obj)

Definition

var proto = {};
var obj = Object.create(proto);
Object.getPrototypeOf(obj) === proto; // true

Term

Object.is(value1, value2);

Definition
  • both undefined
  • both null
  • both true or both false
  • both strings of the same length with the same characters
  • both the same object
  • both numbers and =
Term

Object.isExtensible(obj);

Definition

Objects are extensible by default: they can have new properties added to them, and (in engines that support __proto__ their __proto__ property) can be modified. An object can be marked as non-extensible using Object.preventExtensions(), Object.seal(), or Object.freeze().

Term

Object.isFrozen(obj);

Definition
An object is frozen if and only if it is not extensible, all its properties are non-configurable, and all its data properties (that is, properties which are not accessor properties with getter or setter components) are non-writable.
Term

Object.isSealed(obj);

Definition

Returns true if the object is sealed, otherwise false. An object is sealed if it is not extensible and if all its properties are non-configurable and therefore not removable (but not necessarily non-writable).

Term

Object.keys(obj);

Definition
Object.keys() returns an array whose elements are strings corresponding to the enumerable properties found directly upon object. The ordering of the properties is the same as that given by looping over the properties of the object manually.
Term

Object.preventExtensions(obj);

Definition
An object is extensible if new properties can be added to it. Object.preventExtensions() marks an object as no longer extensible, so that it will never have properties beyond the ones it had at the time it was marked as non-extensible. Note that the properties of a non-extensible object, in general, may still be deleted. Attempting to add new properties to a non-extensible object will fail, either silently or by throwing a TypeError (commonly, but not exclusively, when in strict mode).
Term

obj.hasOwnProperty(prop);

Definition
Every object descended from Object inherits the hasOwnProperty method. This method can be used to determine whether an object has the specified property as a direct property of that object; unlike the in operator, this method does not check down the object's prototype chain.
Term

Object.getOwnPropertySymbols()

Definition

Similar to Object.getOwnPropertyNames(), you can get all symbol properties of a given object as an array of symbols. Note that Object.getOwnPropertyNames() itself does not contain the symbol properties of an object and only the string properties.

As all objects have no own symbol properties initially, Object.getOwnPropertySymbols() returns an empty array unless you have set symbol properties on your object.

Term

Object.getPrototypeOf(obj);

Definition

The prototype of the given object. If there are no inherited properties, null is returned.

Term

Function.length

Definition
a property of a function object, and indicates how many arguments the function expects, i.e. the number of formal parameters. This number excludes the rest parameter and only includes parameters before the first one with a default value. By contrast, arguments.length is local to a function and provides the number of arguments actually passed to the function.
Term

Function.prototype.apply();

func.apply(thisArg, args);

Definition

The apply() method calls a function with a given this value and arguments provided as an array (or an array-like object).

Term

Function.prototype.bind()

func.bind(thisArg, arg1, ...);

Definition
The bind() method creates a new function that, when called, has its this keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.
Term

Function.prototype.call()

func.call(thisArg, arg1, ...);

Definition
The call() method calls a function with a given this value and arguments provided individually.
Term

function.toString()

Definition

The Function object overrides the toString method inherited from Object;

For Function objects, the toString method returns a string representation of the object in the form of a function declaration. That is, toString decompiles the function, and the string returned includes the function keyword, the argument list, curly braces, and the source of the function body.

Term

Error

new Error([message[, fileName[, lineNumber]]])

Definition
The Error constructor creates an error object. Instances of Error objects are thrown when runtime errors occur. The Error object can also be used as a base object for user-defined exceptions. See below for standard built-in error types.
Term

Number

Definition

The Number JavaScript object is a wrapper object allowing you to work with numerical values. A Number object is created using the Number() constructor.

  • If the argument cannot be converted into a number, it returns NaN.
  • In a non-constructor context (i.e., without the new operator), Number can be used to perform a type conversion.
Term

What arg is passed to the contructor of a Promise?

Definition

An 'Executor' function. The Executor is passed the resolve and reject methods.

The Executor is execute *immediately*, and normally calls an asynchronus task.

The Executor is responsible for calling resolve() or reject() to fulfill the promise.

Term

What is __proto__ ?

Definition
An objects prototype property. It's only available in ES6.
Term

let car = { engine: 'v8' };

let vehicle = { model: 'VW' }

vehicle.__proto__ = car;


What is vehicle.engine ?

What is vehicle.car ?

Definition

vehicle.engine is 'V8', accessed through __proto__

vehicle.car is undefined. 'car' is the proto (like a base class), not a property.

Term

let car = { engine: 'v8' };

let vehicle = { model: 'VW' }

vehicle.__proto__ = car;

console.log(vehicle.__proto__);


What is the output of console.log() ?

Definition

{ engine: 'v8' }


__proto__ is the actual object that it points to. But the properties of __proto__ can be accessed as if they are properities of the object.

Term

var alien = { kind: 'alien' };
var zippy = {};
zippy.__proto__ = alien;
zippy.kind = 'zippy';
console.log(zippy.kind);
console.log(alien.kind);


What are the values of zippy.kind and alien.kind

Definition

zippy.kind === 'zippy'

alien.kind === 'alien'


The assignmentaddeda .kind property to zippy.

It has NO effect on the value of the __proto__


Term

let machine = {parts: ['one'], capabilities: {}};

let robot = {}; let vehicle = {};

robot.__proto__ = machine;

vehicle.__proto__ = machine;

robot.parts.push('two')

What is .parts on each object?

Definition

machine.parts === ['one', 'two'];

robot.parts === ['two'];

vehicle.parts === ['one', 'two'];

The assignment to robot overrides the connection to the parts array in the machine __proto__, AND yet adds the object on the array.

Term

What's the function of the prototype?

Why not use inheritance?

let protoObj = { sharedProperty: 'any' }

let obj = Object.create(protoObj)

obj.sharedProperty === 'any'

Definition

The prototype allows you to have many objects sharing fuctionality. One set of functions in memory can be used by any number of objects.

Second, you can dynamically add functionality to multiple objects which share a prototype.

Term
var machine = {};
let robot = Object.create(machine);
let robby = Object.create(robot);
machine.isPrototypeOf(robby) === ?

will machine.isPrototypeOf(robby) return true or false?

Definition

TRUE

It's a prototype chain. Each prototype in the chain qualifies for the object

Supporting users have an ad free experience!