JS Essentials Flashcards

Notes from Lynda.com JS Essentials (55 cards)

1
Q

Are variables uppercase or lowercase

A

Start with lowercase, then use camelcase

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

Are objects and constants uppercase or lowercase

A

Objects and classes start with uppercase, constants are all caps

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

what do you end each statement with

A

a semicolon

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

how do you set a variable as a string

A

var sting=”string full of words”

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

How do you deal with quotation marks in a string when declaring a variable

A
Escape the quotes
var escQuote = "quotes can be \"escaped\"."
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

how do you find the data type of a variable

A

console.log(typeof variableName);

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

what are the data types of variables

A

numeric, string, bollean, null, undefined, symbol

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

Math:
how do you increment a variable by 1?
subtract by 1?

A

var a;
a++;

or
a–;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
Math:
var a=1;
what are the results of the following:
console.log (a);
console.log (++a);
console.log (a++);
A

console. log (a); produces 1
console. log (++a); produces 2
console. log (a++);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
var a = 4;
var b = "5";
var sum = a + b;
console.log (sum);
A

45

because 5 is a string it assumes you are combining strings

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
var a = 4;
var b = "5";
var subt = a-b; 
var mult = a*b; 
var div = a/b;
A

console.log (subt); -1
console.log (mult); 20
console.log (div); .8
because you are not using + it assumes 5 is a number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
var a = 5;
var b = '5';
var theNumbersMatch;
if ( a ==b ){
	theNumbersMatch = true;
	} else {
	theNumbersMatch =  false;
	}
console.log ("the numbers match: " + theNumbersMatch);
A

True because the string of 5 is 5

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

How do you write
if a equals b and c equals d
if a equals b or c equals d
if a equals b xor c equals d

A

if (a == b && c == d) {}
if ( a == b || c== d) {}
if (( a == b || c == d) && (( a == b) ! = (c ==d)) {}

//AND - both a and b are true
//OR - either a or b are true or BOTH
//xor if a equals b xor c equals d (not both)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
rewrite the following as a ternary operator
if ( a==b){
	console.log("match");
 } else {
	console.log ("no match");
	}
A

a == b ? console.log (“match”) : console.log(“no mactch”);

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

var pens = [“red”, “blue”, “green”, “orange”];

how do you find the orange based upon its position?
how do you change the value in the array by referring to its position?

A
var fourthPen = pens[3];
console.log (fourthPen);

pens [3] = “purple”;

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

var pens = [“red”, “blue”, “green”, “orange”];

how do you find the length of the array?

A

console.log (“array length:”, pens.length);

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

var pens = [“red”, “blue”, “green”, “orange”];

How do you reverse the array?

A

console.log(pens.reverse());

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

var pens = [“red”, “blue”, “green”, “orange”];

how do you return the first value of the array?

A

console.log (pens.shift());

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

var pens = [“red”, “blue”, “green”, “orange”];

how do you add values to the front of the array

A

pens.unshift(“purple”, “black”);

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

var pens = [“red”, “blue”, “green”, “orange”];

how do you remove the last value of the array

A

console.log (pens.pop());

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

var pens = [“red”, “blue”, “green”, “orange”];

how do you add values to the end of the array

A

pens.push (“pink”, “prussian blue”);

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

var pens = [“red”, “blue”, “green”, “orange”];

How do you take blue away from the array?

A

pens.splice (1,1);

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

var pens = [“red”, “blue”, “green”, “orange”];

how do you make a copy of an array?

A

var newPens = pens.slice();

24
Q

var pens = [“red”, “blue”, “green”, “orange”];

how do you return the values of the array in a comma separated list?

A
var arrayString = pens.join(separator);
console.log('string from array: ', arrayString);
25
what are the three types of functions and when do they execute
named - when called anonymous - run once they are triggered by an event immediately invoked - when the browser encounters them
26
What is variable scope?
Where the variable will be used. Either global or local. Global - you can access it anywhere in the script. If you change it in a function it is changed globally. Local - if you declare a variable in a function then it is local to that function and cannot be used outside of it.
27
what is the scope of a let statement
let is a block scope variable - it can only be used in that statement
28
Are objects written as lowercase, uppercase or camelcase?
Objects are capitalized
29
what are the three types of functions
named, anonymous, immediately invoked
30
what are the 4 ways to invoke a function
1. as a function 2. as methods 3. constructors 4. call and apply methods
31
when does an immediately invoked expression happen
when the browser encounters them
32
what is a constant
can't be changed once defined
33
what is a let
a block scope variable, only available in that function
34
are objects capitalized or lower case
capitalized
35
``` var a = 4; var b = "5"; var sum = a + b; ```
produces 45 because javascript assumes you want a string since 5 is a string
36
``` ar a = 4; var b = "5"; var subt = a-b; var mult = a*b; var div = a/b; ```
``` var subt = a-b; //will produce 1 var mult = a*b; //20 var div = a/b; //.8 ```
37
what is the difference between: = == ===
= is assignment == equal === strictly equal
38
``` var a = 5; var b = '5'; var theNumbersMatch; ``` ``` if ( a ==b ){ theNumbersMatch = true; } else { theNumbersMatch = false; } would produce what? ```
true, because the string of 5 is 5
39
``` var a = 5; var b = '5'; var theNumbersMatch; ``` ``` if ( a === b ){ theNumbersMatch = true; } else { theNumbersMatch = false; } would produce what? ```
false
40
``` //boolean if (a ==true) {} what is the shorthand ```
if (a) {}
41
write: | if a equals b and c equals d
if (a == b && c == d) {}
42
write: | if a equals b or c equals d
if ( a == b || c== d) {}
43
write | if a equals b or c equals d OR BOTH
if ( a == b || c== d) {}
44
``` write this as a ternary operator if ( a==b){ console.log("match"); } else { console.log ("no match"); } ```
a == b ? console.log ("match") : console.log("no mactch");
45
var pens; pens = new Array ["red", "blue", "green", "orange"]; find the fourth value in the array
``` var fourthPen = pens[3]; console.log (fourthPen); ```
46
var pens; pens = new Array ["red", "blue", "green", "orange"]; Change the fourth value in the array to purple
pens [3] = "purple";
47
var pens; pens = ["red", "blue", "green", "orange"]; find how many elements are in the array
console.log ("array length:", pens.Length); //returns 4
48
var pens; pens = ["red", "blue", "green", "orange"]; how to you reverse the array? remove the first value of the array? remove the last value? find a specific position and remove it?
there are many standard methods to manipulate arrays pens. reverse(); pens. shift() pens. pop() pens. splice (pos, n)
49
var pens; pens = ["red", "blue", "green", "orange"]; how do you create a copy of an array and assign it to a new variable
use the slice method ``` var newPens = pens.slice(); console.log("new pens:", newPens); ```
50
What is hoisting?
javascript moves all declarations to the top if you declare anything at the bottom but run it at the top it will work. the only time it won't work is if you declare it at the bottom and assign a value, but then call it at the top, it will be undefined.
51
how would you run this? ``` var a = 5/7; var b = 18/25; ``` ``` var theBiggest = function(){ var result; a>b ? result = ["a",a] : result = ["b", b]; console.log(result); } ```
theBiggest(); or to get it to display: console.log(theBiggest());
52
What is the difference between global and local scope
global - in the root you can access anywhere in the script if you make a change to it inside a fuction then it is changed globally if you declare var in a funtion then it is local and cannot be used ouside of that function
53
what is the difference between constant and let
constant can't be changed once defined | let is a block scope variable - smaller scope
54
are objects lowercase, capitalized or camelcase?
capitalized
55
how do you define an object and its properties?
var course = new Object(); //then define the properties of the object course. title = "java training"; course. instructor = "joe smith"; course. level = 1; course. published = true; ``` //or shorthand var course = new Object(); var course = { title: "java training", instructor: "heather morris", level: 1, published: true, } ```