Basic Syntax Flashcards

1
Q

JS: console.log()

A

‘Print’ to screen

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

JS: .length

A

Return the length of a string variable

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

JS: . toUpperCase()

A

Change string to capitals

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

JS: . startsWith(n)

A

Returns a Boolean depending on your input value -(n)

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

JS: .trim()

A

Removes white space!
Also trimEnd or trimStart

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

JS: Math.random()

A

Return a random number between 0 and <1

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

JS: Math.floor()

A

Round down a decimal to nearest int

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

JS: Math.ceil(Math.random() * n);

A

Round up a decimal to nearest int with random number gen

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

JS: Number.isInteger()

A

Checks variable (number) and Returns a Boolean

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

What are the 7 fundamental data types in JS?

A

Strings
Numbers
Booleans
Null
Undefined
Symbol
Object

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

JS: let var =
const var. =

A

Use to assign a variable

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

JS: let

A

Signals a variable can be reassigned a new value

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

JS: const

A

Assign an immutable variable

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

JS: some string with ${someVar) included ;

A

String interpolating (bit like a python f-string)

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

JS: typeof
Eg. console.log(typeof myVar);

A

To return the data type of the stored value.

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

JS: if (condition) {
//execute this code
} else {
// execute this code
}

A

Basic conditional

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

JS: What’s the ‘and’ operator

A

&&

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

JS: What’s the ‘or’ operator?

A

||

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

JS: What’s the ‘not’ operator?

A

!

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

JS: Give the ‘falsy’ values.

A

0 , “” , null, undefined, NaN

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

JS: let VAR = VAR || ‘fresh input’

A

Short circuit evaluation

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

JS: VAR ? execute code : execute code;

A

Ternary operator
Checks if VAR is true then else

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

JS: const someVar = function () {
}

A

A function expression (anonymous function)

24
Q

JS: const someVar = () => {
}

A

An arrow function

25
JS: const = someVar = param => num * num;
Concise body function () removed from someVar {} removed since only a single line function Return is implicit Would otherwise like like const someVar = (num) => { return num * num; };
26
JS: STRING[n];
Access an index of a string
27
JS: STRING.slice(indexinc, indexex);
Get a slice (range of characters) from a string. NB: lower index is inclusive, upper is exclusive
28
JS: array.push(INPUT);
Add an element to the end of an array Returns the new length
29
JS: array.unshift(INPUT);
Adds an element to the start of an array.
30
JS: array.pop();
Remove the last element from an array. Method returns the removed value.
31
JS: array.shift()
Removes first element (value not index) from an array return the value
32
JS: new array = array1.concat(array2);
Combine 2 arrays to create new (and leaving the old ones unchanged
33
JS: array .indexOf(INPUT);
find the index location of the input value
34
JS: array.join();
Turn the array into a string. You can input your own separator choice as an argument: e.g .join(“, “)
35
JS: array.includes(INPUT)
returns true or false
36
JS: array. revers();
Modifies the original! Otherwise self explanatory
37
JS: array.sort((a, b) => a -b);
modifies the original sort ascending or do b- a for descending
38
JS: array.slice(index, index)
creates a new array from the slice, end index is not included)
39
JS: array.splice(index, count, optionalItem);
Removes ‘count’ elements from array starting at ‘index’ or from 0 index if no index included. optionalItem added to the array from indeed
40
JS: obj[‘key n’]; Or obj.keyn (if valid identifier)
Retrieve a value from an object but its key
41
JS: object[‘key’] = value; Or. object.key = value;
Add or replace a key-value pair
42
JS: Object. keys(OBJECT);
Returns the keys of the object as an array
43
JS: Object.entries(OBJECT);
returns a 2d array of key-value pairs
44
JS: JSON.stringify(nestedObject);
Returns a JSON represented string of nested object
45
JS: setTimeout(yourArg, msdelay)
Delay function. Second argument is delay in milliseconds.i.e 1000 for 1 second
46
JS: passing a function as an argument?
Don’t use ()
47
JS: ARRAY.find(item => itemCRITERA);
Find the first element in a array that matches criteria
48
JS: ARRAY.filter(item => itemCRITERA);
Returns a new array with elements that pass the test implemented by the function
49
JS: ARRAY.map( ITEM => function content);
Returns a new array with the results of function on every element
50
JS: Math.hypot(dx, dy);
Find the hypotenuse; straight line distance between points x and y
51
JS: array.indexOf(“element”)(
Returns the index num of the element
52
JS. array.splice (start index, num of indices, replacement)
Swap out part of an array
53
JS: array.reduce((acc, curr) => acc + curr, 0)
Executes a reducer function on each element resulting in single value output
54
array.forEach(item => function)
Execute function on each item
55
Object.assign(target, source)
Copies (and overwrites if existing values) properties from source object to target, then returns the target