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
How are arrays different from "plain" objects?
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.
26
What number represents the first index of an array?
array[0]
27
What is the length property of an array?
how many number of item in array
28
How do you calculate the last index of an array?
array.length-1
29
What is a function in JavaScript?
a set of code we can reuse, and deal with information .
30
Describe the parts of a function definition.
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.
31
Describe the parts of a function call.
call with argument
32
When comparing them side-by-side, what are the differences between a function call and a function definition?
call give argument, definition set pramater.
33
What is the difference between a parameter and an argument?
parameter is the placeholder argument is the actually value
34
Why are function parameters useful?
Parameters allow us to pass information or instructions into functions and procedures .
35
What two effects does a return statement have on the behavior of a function?
return value close functiuon
36
Why do we log things to the console?
debug
37
What is a method?
JavaScript Methods: A JavaScript method is a property of an object that contains a function definition. Methods are functions stored as object properties.
38
How is a method different from any other function?
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
How do you remove the last element from an array?
array.length-1
40
How do you round a number down to the nearest integer?
Math.floor()
41
How do you generate a random number?
var randomNumber = Math.random(); randomNumber = randomNumber * heroes.length;
42
How do you delete an element from an array?
array.pop
43
How do you append an element to an array?
array.push
44
How do you break a string up into an array?
array.split(' ')
45
Do string methods change the original string? How would you check if you weren't sure?
no, log
46
Is the return value of a function or method useful in every situation?
no. sometimes just do some stuff, no return value
47
Give 6 examples of comparison operators.
< > = && || >= <=
48
What data type do comparison expressions evaluate to?
boolean
49
What is the purpose of an if statement?
if something is true, do it
50
Is else required in order to use an if statement?
no
51
Describe the syntax (structure) of an if statement.
if (xxx) {do xxx}
52
What are the three logical operators?
> = <
53
How do you compare two different expressions in the same condition?
==
54
What is the purpose of a loop?
loop through code, processing again and again until it meet expectations
55
What is the purpose of a condition expression in a loop?
set loop times etc
56
What does "iteration" mean in the context of loops?
loop through code, processing again and again until it meet expectations
57
When does the condition expression of a while loop get evaluated?
until give situations is false
58
When does the initialization expression of a for loop get evaluated?
until give situations is break
59
When does the final expression of a for loop get evaluated?
60
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
61
How do you iterate through the keys of an object?
use for..in.. loop
62
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse
63
serialization and deserialization?
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
What is JSON?
The JSON object contains methods for parsing JavaScript Object Notation (JSON) and converting values to JSON. It can't be called or constructed.
65
Why are serialization and deserialization useful?
serialization is easy to sent, turn data to easy to transfer deserialization is easy to work with
66
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify()
67
How do you store data in localStorage?
keyname
68
How do you retrieve data from localStorage?
getItem('key', value)
69
What data type can localStorage save in the browser?
string
70
When does the 'beforeunload' event fire on the window object?
refresh page, close tab, etc (anything make the page closed)
71
What is a method?
A method is a function which is a property of an object.
72
How can you tell the difference between a method definition and a method call?
method definition: function assign to proprety in the object method call: call the function assign to the object property with parameter
73
Describe method definition syntax (structure).
74
Describe method call syntax (structure).
object dot
75
How is a method different from any other function?
dot notation
76
What is the defining characteristic of Object-Oriented Programming?
objects can contain both data (as properties) and behavior (as methods).
77
What are the four "principles" of Object-Oriented Programming?
Abstraction Encapsulation Inheritance Polymorphism
78
What is "abstraction"?
being able to work with (possibly) complex things in simple ways.
79
What does API stand for?
80
What is the purpose of an API?
tools allow user interface programs with data
81
What is this in JavaScript?
the object you are currently working with
82
What does it mean to say that this is an "implicit parameter"?
implicit: presented but not stated
83
When is the value of this determined in a function; call time or definition time?
call time. cause when definition time the parameter dose not have value
84
How can you tell what the value of this will be for a particular function or method definition?
you can't
85
How can you tell what the value of this is for a particular function or method call?
if is xxx.jj() this is xxx if is xxx() this is window
86
window
window is a object, everything is in window object