Javascript Flashcards

1
Q

<p>+</p>

A

<p>Returns the sum or 2 numbers or concatenates 2 strings</p>

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

<p>%</p>

A

<p>Modulo Returns the remainder of the first value divided by the second</p>

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

Javascript Primitive Data Types(5)

A

String, Number, Boolean, Null, Undefined

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

<p>2 + "2"</p>

A

<p>Concatenation = 22</p>

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

10 > 2

A

returns true

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

typeof()

A

tells us what the type is typeOf(10<2) returns boolean

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

Javascript Null

A

A value does not exist

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

Javascript Undefined

A

The variable has yet to be defined

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

Javascript prompt

A

Creates and alert box that accepts an input; var x = prompt(“what is x”);

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

Random number between 0 and 5

A

var _randNum = Math.round(Math.random() * 5);

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

Check if number is divisible by 3

A

if (x%3 === 0)

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

Property

A

Values of an object Dog.breed breed is property; noun

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

Method

A

A function that is associated with an object; verb

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

object literal

A

Define and create an instance at the same time var person = {Name: “Bill”, Age: 5}

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

object constructor

A

function Person (name, age) {this.name = name; this.age = age;}

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

Host objects

A

Objects defined by the environment; console is a common host object used in a browser

17
Q

Core objects

A

Objects defined by Javascript examples: Math, String, Boolean, Array

18
Q

global object

A

The window is the global object when the host environment is the web; window.alert() === alert()

19
Q

Local Scope

A

Variables created inside a function can’t be accessed from outside the function. (Variables created within a function that do not use the var keyword are added to global scope)

20
Q

Function scope

A

Every time we create a new function the scope changes

21
Q

Closure dictionary definition

A

A combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment)

22
Q

Closure laymans definition

A

A closure gives you access to an outer functions scope from an inner function. In JS closures are created every time a function is created at function creation time.

23
Q

Why are closures used

A

To give objects data privacy; variables can be manipulated in a different scope

24
Q

Closure benfites

A

Keep dataprivate;

25
``` var output = (function(x) { delete x; return x; })(0); ``` console.log(output);
Above code will output 0 as output. delete operator is used to delete a property from an object. Here x is not an object it's local variable. delete operator doesn't affect local variable.
26
What is “closure” in javascript? Provide an example?
A closure is a function defined inside another function (called parent function) and has access to the variable which is declared and defined in parent function scope.
27
difference between let and var
var is scoped to the nearest function block; let is scoped to the nearest enclosing block
28
If i already have an array and i want to do the exact same operation on each of the elements in the array and return the same amount of items in the array
Map
29
If i already have an array but i only want to have items in the array that match certain criteria
Filter
30
If i already have an array, but i want to use the values in that array to create something completely new
Reduce