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
Q

JS: const = someVar = param => num * num;

A

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
Q

JS: STRING[n];

A

Access an index of a string

27
Q

JS: STRING.slice(indexinc, indexex);

A

Get a slice (range of characters) from a string.
NB: lower index is inclusive, upper is exclusive

28
Q

JS: array.push(INPUT);

A

Add an element to the end of an array
Returns the new length

29
Q

JS: array.unshift(INPUT);

A

Adds an element to the start of an array.

30
Q

JS: array.pop();

A

Remove the last element from an array. Method returns the removed value.

31
Q

JS: array.shift()

A

Removes first element (value not index) from an array return the value

32
Q

JS: new array = array1.concat(array2);

A

Combine 2 arrays to create new (and leaving the old ones unchanged

33
Q

JS: array .indexOf(INPUT);

A

find the index location of the input value

34
Q

JS: array.join();

A

Turn the array into a string. You can input your own separator choice as an argument: e.g .join(“, “)

35
Q

JS: array.includes(INPUT)

A

returns true or false

36
Q

JS: array. revers();

A

Modifies the original! Otherwise self explanatory

37
Q

JS: array.sort((a, b) => a -b);

A

modifies the original sort ascending or do b- a for descending

38
Q

JS: array.slice(index, index)

A

creates a new array from the slice, end index is not included)

39
Q

JS: array.splice(index, count, optionalItem);

A

Removes ‘count’ elements from array starting at ‘index’ or from 0 index if no index included.
optionalItem added to the array from indeed

40
Q

JS: obj[‘key n’];
Or obj.keyn (if valid identifier)

A

Retrieve a value from an object but its key

41
Q

JS: object[‘key’] = value;
Or. object.key = value;

A

Add or replace a key-value pair

42
Q

JS: Object. keys(OBJECT);

A

Returns the keys of the object as an array

43
Q

JS: Object.entries(OBJECT);

A

returns a 2d array of key-value pairs

44
Q

JS: JSON.stringify(nestedObject);

A

Returns a JSON represented string of nested object

45
Q

JS: setTimeout(yourArg, msdelay)

A

Delay function. Second argument is delay in milliseconds.i.e 1000 for 1 second

46
Q

JS: passing a function as an argument?

A

Don’t use ()

47
Q

JS: ARRAY.find(item => itemCRITERA);

A

Find the first element in a array that matches criteria

48
Q

JS: ARRAY.filter(item => itemCRITERA);

A

Returns a new array with elements that pass the test implemented by the function

49
Q

JS: ARRAY.map( ITEM => function content);

A

Returns a new array with the results of function on every element

50
Q

JS: Math.hypot(dx, dy);

A

Find the hypotenuse; straight line distance between points x and y

51
Q

JS: array.indexOf(“element”)(

A

Returns the index num of the element

52
Q

JS. array.splice (start index, num of indices, replacement)

A

Swap out part of an array

53
Q

JS: array.reduce((acc, curr) => acc + curr, 0)

A

Executes a reducer function on each element resulting in single value output

54
Q

array.forEach(item => function)

A

Execute function on each item

55
Q

Object.assign(target, source)

A

Copies (and overwrites if existing values) properties from source object to target, then returns the target