Chapter 1 Flashcards

(49 cards)

1
Q

Official name for JavaScript

A

ECMAScript

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

ECMAScript

A

A standardized version of javascript that is compatible with various browsers.

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

//

A

Single line comments start with //.

Any text between // and the end of the line will be ignored by JavaScript (will not be executed).

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

/* */

A

Multi-line comments start with /* and end with */.

Any text between /* and */ will be ignored by JavaScript.

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

A variable is declared (created) with a

A

;

Ex. var x;

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

Describe: x=3+y;

A

Assigning a value to the variable x

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

Describe: foo(x,y);

A

calling function foo with parameters x and y

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

obj.bar(3)

A

calling method ‘bar’ of object ‘obj’

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

conditional statement example

A

if (x===0) {
return “Try Again”;
}

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

= vs ===

A

=== is more strict of an equality

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

x+=1 equivalent

A

x=x+1

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

.length

A
outputs the number of characters in a variable or value
Ex: 
var str="abc"
str.length
3 //output is 3
Ex. "abc".length
3 //output is 3
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

how to assign a value to a property

A

you must declare an object, add a property to the object, then assign a value to the property
Ex.
var obj={}; //empty object
obj.foo=123; // create property foo, set it to 123
obj.foo
123 //output is 123

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

.toUpperCase()

A

turns precedent characters to all capital letters
“hello”.toUpperCase()
HELLO

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

can two empty objects be strictly equal to each other

A
No. Each object has a unique identity and is only strictly equal to itself
ex.:
var obj1={};
var obj2={};
obj1===obj2
false
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

string example

A

“abc”

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

boolean example

A

4===2;
false
or 2===2
true

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

how to add multiple properties to an object

A
var obj={
firstName: "ayden",
lastName: "licea"};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

operator for describing the “type” of value

A

typeof
ex.
typeof true
‘boolean’

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

increment

23
Q

remainder

24
Q

new line

25
how to access single characters of a string
var str = 'abc'; str[ 1] 'b'
26
how to count number of characters in a string
ex. "abc".length 3
27
how to concatenate strings in multiple steps
``` use += ex. var str = ''"; str += 'Multiple '; str += 'pieces '; str += 'are concatenated.'; str 'Multiple pieces are concatenated.' ```
28
how to slice characters out of a string
'abc'. slice( 1) // copy a substring 'bc' 'abc'. slice( 1, 2) // 1=slice starting point. 2=slice ending point 'b'
29
how to get rid of white space in a string
.trim //removes white space from the beginning and/or end of a string ex. var str = " Hello World! "; alert(str.trim());
30
how to create a button
button title
31
how to add functionality to a button
``` onclick Try it //executes a function when user clicks //button named 'Try it' ```
32
how to find a character location in a string
.indexOf > 'abc'. indexOf(' b') // find a string 1
33
how to add items to the end of an array
``` .push() ex. var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.push(",Kiwi"); Banana,Orange,Apple,Mango,Kiwi ```
34
what base is the length property
``` one-based ex. var arr = [1, 2, 3, 4, 5]; console.log(arr.length); //4 ```
35
what base is an array index
zero-based
36
slice() method
The slice() method returns the selected elements in an array, as a new array object. The slice() method selects the elements starting at the given start argument, and ends at, but does not include, the given end argument. ex. var arr = [1,2,3,4,5,6]; console.log(arr.slice(2,5)) //3,4,5 ex. var animals = ['ant', 'bison', 'camel', 'duck', 'elephant']; console.log(animals.slice(2)); //camel, duck, elephant ``` console.log(animals.slice(2, 4)); //camel, duck ```
37
.trim()
tims whitespace ``` var str = " Hello World! "; alert(str.trim()); //Hello World! /* instead of: Hello World!*/ ```
38
.toUpperCase()
``` 'mjölnir'. toUpperCase() //MJÖLNIR ```
39
.indexOf()
``` 'ayden'.indexOf('d'); //2 ```
40
how to get a negative number output from .indexOf()
The indexOf method returns the beginning of the substring in the String object. If the substring is not found, -1 is returned. ``` 'abcd'.indexOf('j'); //-1 ```
41
and
&&;
42
else if statement format
``` if () { //then } else if () { //else-if } else { //else } ```
43
switch statement format
``` ex. 1 switch (expression) { case value1: //Statements executed when the //result of expression matches value1 break; case value2: //Statements executed when the //result of expression matches value2 break; ``` ``` ex. 2 case valueN: //Statements executed when the //result of expression matches valueN break; default: //Statements executed when none of //the values match the value of the expression break; } ex. 3 var expr = 'Papayas'; switch (expr) { case 'Oranges': console.log('Oranges are $0.59 a pound.'); break; case 'Mangoes': case 'Papayas': console.log('Mangoes and papayas are $2.79 a pound.'); // expected output: "Mangoes and papayas are $2.79 a pound." break; default: console.log('Sorry, we are out of ' + expr + '.'); } ```
44
for loop format
for (initial statement, condition, post-iteration) { code block to be executed } ``` ex. var cars = ["BMW", "Volvo", "Saab", "Ford", "Fiat", "Audi"]; var text = ""; var i; for (i = 0; i < cars.length; i++) { text += cars[i] + "
"; } document.getElementById("demo").innerHTML = text; } ``` ``` /*output BMW Volvo Saab Ford Fiat Audi */ ex2 ``` ``` for (let i = 0; i < 4; i++) { document.write(i); } ``` //output = 0123
45
x += y equivolent
x = x + y
46
while loop
``` ex. 1 var i= 0; while (i < 10) { document.write(i); i++; } ```
47
break;
ends a loop ex. if (a<10) { break;}
48
two types of javascript values
text and numbers
49
how to make a variable a string
make it equal to "" ex. var str="";