JavaScript Flashcards
object literal
var xxx = {}
I can literally see the object
What is the purpose of variables?
to create a memory space for restore values
How do you declare a variable?
var const let
How do you initialize (assign a value to) a variable?
use = == ===
What characters are allowed in variable names?
The period, the underscore, and the characters $, #, and @ can be used within variable names. For example, A. _$@#1 is a valid variable name.
What does it mean to say that variable names are “case sensitive”?
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.
What is the purpose of a string?
text information
What is the purpose of a number?
numerical information
What is the purpose of a boolean?
true or false
What does the =, ==, === operator mean in JavaScript?
= 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 do you update the value of a variable?
write the name, reassign value
What is the difference between null and undefined?
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
Why is it a good habit to include “labels” when you log values to the browser console?
nice and clear on what are we log in
Give five examples of JavaScript primitives.
undefined , null , boolean , string and number
bigint. for restore crazy big number (astro, bunisess data)
symbol.
What data type is returned by an arithmetic operation?
number
What is string concatenation?
var string += xxx
What purpose(s) does the + plus operator serve in JavaScript?
plus things
What data type is returned by comparing two values (<, >, ===, etc)?
boolean
What does the += “plus-equals” operator do?
Exercise
ob += x
ob = ob + x
What are objects used for?
{xx:pp, xx:pp} like dictionary
What are object properties?
{xx:pp, xx:pp} xx is the property
How do you remove a property from an object?
delete object.object property
What are the two ways to get or update the value of a property?
object.property = value
object[‘property’] = value
What are arrays used for?
restore a list can be count, loop
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.
What number represents the first index of an array?
array[0]
What is the length property of an array?
how many number of item in array
How do you calculate the last index of an array?
array.length-1
What is a function in JavaScript?
a set of code we can reuse, and deal with information .
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.
Describe the parts of a function call.
call with argument
When comparing them side-by-side, what are the differences between a function call and a function definition?
call give argument, definition set pramater.
What is the difference between a parameter and an argument?
parameter is the placeholder
argument is the actually value
Why are function parameters useful?
Parameters allow us to pass information or instructions into functions and procedures .
What two effects does a return statement have on the behavior of a function?
return value
close functiuon
Why do we log things to the console?
debug
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.
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.
How do you remove the last element from an array?
array.length-1
How do you round a number down to the nearest integer?
Math.floor()
How do you generate a random number?
var randomNumber = Math.random();
randomNumber = randomNumber * heroes.length;
How do you delete an element from an array?
array.pop
How do you append an element to an array?
array.push
How do you break a string up into an array?
array.split(‘ ‘)
Do string methods change the original string? How would you check if you weren’t sure?
no, log
Is the return value of a function or method useful in every situation?
no. sometimes just do some stuff, no return value
Give 6 examples of comparison operators.
< > = && || >= <=
What data type do comparison expressions evaluate to?
boolean
What is the purpose of an if statement?
if something is true, do it
Is else required in order to use an if statement?
no
Describe the syntax (structure) of an if statement.
if (xxx) {do xxx}
What are the three logical operators?
> = <
How do you compare two different expressions in the same condition?
==
What is the purpose of a loop?
loop through code, processing again and again until it meet expectations
What is the purpose of a condition expression in a loop?
set loop times etc
What does “iteration” mean in the context of loops?
loop through code, processing again and again until it meet expectations
When does the condition expression of a while loop get evaluated?
until give situations is false
When does the initialization expression of a for loop get evaluated?
until give situations is break
When does the final expression of a for loop get evaluated?
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
How do you iterate through the keys of an object?
use for..in.. loop
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse
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
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.
Why are serialization and deserialization useful?
serialization is easy to sent, turn data to easy to transfer
deserialization is easy to work with
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify()
How do you store data in localStorage?
keyname
How do you retrieve data from localStorage?
getItem(‘key’, value)
What data type can localStorage save in the browser?
string
When does the ‘beforeunload’ event fire on the window object?
refresh page, close tab, etc (anything make the page closed)
What is a method?
A method is a function which is a property of an object.
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
Describe method definition syntax (structure).
Describe method call syntax (structure).
object dot
How is a method different from any other function?
dot notation
What is the defining characteristic of Object-Oriented Programming?
objects can contain both data (as properties) and behavior (as methods).
What are the four “principles” of Object-Oriented Programming?
Abstraction
Encapsulation
Inheritance
Polymorphism
What is “abstraction”?
being able to work with (possibly) complex things in simple ways.
What does API stand for?
What is the purpose of an API?
tools allow user interface programs with data
What is this in JavaScript?
the object you are currently working with
What does it mean to say that this is an “implicit parameter”?
implicit: presented but not stated
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
How can you tell what the value of this will be for a particular function or method definition?
you can’t
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
window
window is a object, everything is in window object