JavaScript Flashcards

1
Q

object literal

A

var xxx = {}
I can literally see the object

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

What is the purpose of variables?

A

to create a memory space for restore values

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

How do you declare a variable?

A

var const let

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

How do you initialize (assign a value to) a variable?

A

use = == ===

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

What characters are allowed in variable names?

A

The period, the underscore, and the characters $, #, and @ can be used within variable names. For example, A. _$@#1 is a valid variable name.

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

What does it mean to say that variable names are “case sensitive”?

A

JavaScript is a case-sensitive language. This means that language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters.

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

What is the purpose of a string?

A

text information

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

What is the purpose of a number?

A

numerical information

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

What is the purpose of a boolean?

A

true or false

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

What does the =, ==, === operator mean in JavaScript?

A

= assign variable

The equality operator (==) checks whether its two operands are equal, returning a Boolean result. Unlike the strict equality operator, it attempts to convert and compare operands that are of different types.

The strict equality operator (===) checks whether its two operands are equal, returning a Boolean result. Unlike the equality operator, the strict equality operator always considers operands of different types to be different.

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

How do you update the value of a variable?

A

write the name, reassign value

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

What is the difference between null and undefined?

A

null is created by human, means there’s empty for now but not long

Undefined is by machine. telling us item don’t have value

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

Why is it a good habit to include “labels” when you log values to the browser console?

A

nice and clear on what are we log in

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

Give five examples of JavaScript primitives.

A

undefined , null , boolean , string and number

bigint. for restore crazy big number (astro, bunisess data)
symbol.

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

What data type is returned by an arithmetic operation?

A

number

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

What is string concatenation?

A

var string += xxx

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

What purpose(s) does the + plus operator serve in JavaScript?

A

plus things

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

What data type is returned by comparing two values (<, >, ===, etc)?

A

boolean

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

What does the += “plus-equals” operator do?
Exercise

A

ob += x
ob = ob + x

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

What are objects used for?

A

{xx:pp, xx:pp} like dictionary

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

What are object properties?

A

{xx:pp, xx:pp} xx is the property

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

How do you remove a property from an object?

A

delete object.object property

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

What are the two ways to get or update the value of a property?

A

object.property = value
object[‘property’] = value

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

What are arrays used for?

A

restore a list can be count, loop

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

How are arrays different from “plain” objects?

A

Objects represent a special data type that is mutable and can be used to store a collection of data (rather than just a single value). Arrays are a special type of variable that is also mutable and can also be used to store a list of values.

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

What number represents the first index of an array?

A

array[0]

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

What is the length property of an array?

A

how many number of item in array

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

How do you calculate the last index of an array?

A

array.length-1

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

What is a function in JavaScript?

A

a set of code we can reuse, and deal with information .

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

Describe the parts of a function definition.

A

A function has three parts, a set of inputs, a set of outputs, and a rule that relates the elements of the set of inputs to the elements of the set of outputs in such a way that each input is assigned exactly one output.

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

Describe the parts of a function call.

A

call with argument

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

When comparing them side-by-side, what are the differences between a function call and a function definition?

A

call give argument, definition set pramater.

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

What is the difference between a parameter and an argument?

A

parameter is the placeholder
argument is the actually value

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

Why are function parameters useful?

A

Parameters allow us to pass information or instructions into functions and procedures .

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

What two effects does a return statement have on the behavior of a function?

A

return value
close functiuon

36
Q

Why do we log things to the console?

A

debug

37
Q

What is a method?

A

JavaScript Methods: A JavaScript method is a property of an object that contains a function definition. Methods are functions stored as object properties.

38
Q

How is a method different from any other function?

A

A method, like a function, is a set of instructions that perform a task. The difference is that a method is associated with an object, while a function is not.

39
Q

How do you remove the last element from an array?

A

array.length-1

40
Q

How do you round a number down to the nearest integer?

A

Math.floor()

41
Q

How do you generate a random number?

A

var randomNumber = Math.random();
randomNumber = randomNumber * heroes.length;

42
Q

How do you delete an element from an array?

A

array.pop

43
Q

How do you append an element to an array?

A

array.push

44
Q

How do you break a string up into an array?

A

array.split(‘ ‘)

45
Q

Do string methods change the original string? How would you check if you weren’t sure?

A

no, log

46
Q

Is the return value of a function or method useful in every situation?

A

no. sometimes just do some stuff, no return value

47
Q

Give 6 examples of comparison operators.

A

< > = && || >= <=

48
Q

What data type do comparison expressions evaluate to?

A

boolean

49
Q

What is the purpose of an if statement?

A

if something is true, do it

50
Q

Is else required in order to use an if statement?

A

no

51
Q

Describe the syntax (structure) of an if statement.

A

if (xxx) {do xxx}

52
Q

What are the three logical operators?

A

> = <

53
Q

How do you compare two different expressions in the same condition?

A

==

54
Q

What is the purpose of a loop?

A

loop through code, processing again and again until it meet expectations

55
Q

What is the purpose of a condition expression in a loop?

A

set loop times etc

56
Q

What does “iteration” mean in the context of loops?

A

loop through code, processing again and again until it meet expectations

57
Q

When does the condition expression of a while loop get evaluated?

A

until give situations is false

58
Q

When does the initialization expression of a for loop get evaluated?

A

until give situations is break

59
Q

When does the final expression of a for loop get evaluated?

A
60
Q

Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?

A

break

61
Q

How do you iterate through the keys of an object?

A

use for..in.. loop

62
Q

How do you deserialize a JSON string into a data structure using JavaScript?

A

JSON.parse

63
Q

serialization and deserialization?

A

Converting a string to a native object is called deserialization, while converting a native object to a string so it can be transmitted across the network is called serialization.

serialization : make array to JSON string
deserialization: make JSON string to array

64
Q

What is JSON?

A

The JSON object contains methods for parsing JavaScript Object Notation (JSON) and converting values to JSON. It can’t be called or constructed.

65
Q

Why are serialization and deserialization useful?

A

serialization is easy to sent, turn data to easy to transfer
deserialization is easy to work with

66
Q

How do you serialize a data structure into a JSON string using JavaScript?

A

JSON.stringify()

67
Q

How do you store data in localStorage?

A

keyname

68
Q

How do you retrieve data from localStorage?

A

getItem(‘key’, value)

69
Q

What data type can localStorage save in the browser?

A

string

70
Q

When does the ‘beforeunload’ event fire on the window object?

A

refresh page, close tab, etc (anything make the page closed)

71
Q

What is a method?

A

A method is a function which is a property of an object.

72
Q

How can you tell the difference between a method definition and a method call?

A

method definition: function assign to proprety in the object

method call: call the function assign to the object property with parameter

73
Q

Describe method definition syntax (structure).

A
74
Q

Describe method call syntax (structure).

A

object dot

75
Q

How is a method different from any other function?

A

dot notation

76
Q

What is the defining characteristic of Object-Oriented Programming?

A

objects can contain both data (as properties) and behavior (as methods).

77
Q

What are the four “principles” of Object-Oriented Programming?

A

Abstraction
Encapsulation
Inheritance
Polymorphism

78
Q

What is “abstraction”?

A

being able to work with (possibly) complex things in simple ways.

79
Q

What does API stand for?

A
80
Q

What is the purpose of an API?

A

tools allow user interface programs with data

81
Q

What is this in JavaScript?

A

the object you are currently working with

82
Q

What does it mean to say that this is an “implicit parameter”?

A

implicit: presented but not stated

83
Q

When is the value of this determined in a function; call time or definition time?

A

call time. cause when definition time the parameter dose not have value

84
Q

How can you tell what the value of this will be for a particular function or method definition?

A

you can’t

85
Q

How can you tell what the value of this is for a particular function or method call?

A

if is xxx.jj() this is xxx
if is xxx() this is window

86
Q

window

A

window is a object, everything is in window object