JavaScript Flashcards
What is the purpose of variables?
To store data.
How do you declare a variable?
Variable keyword followed by the variable name.
How do you initialize (assign a value to) a variable?
Variable name followed by an assignment operator followed by a variable value.
What characters are allowed in variable names?
letters, numbers, dollar sign, or an underscore. Cannot use dash or a period in a variable name. Cannot use reserved words like var. Cannot start with numbers.
What does it mean to say that variable names are “case sensitive”?
variables, functions, and any other identifiers must be typed with consistent capitalization of letters.
What is the purpose of a string?
holding data that can be represented in text form. To save a series of characters.
What is the purpose of a number?
to represent and manipulate numbers. Represent numeric value. Math, a measurement.
What is the purpose of a boolean?
datatype that returns either true or false. To make decisions. Allow you to tell the computer do or don’t do.
What does the=operator mean in JavaScript?
assignment operator. Putting a value to something.
How do you update the value of a variable?
variable name assignment operator and value
What is the difference between null and undefined?
undefined is a variable thats not assigned to anything. null is when purposely assigned a value of nothing until give value later.
Why is it a good habit to include “labels” when you log values to the browser console?
to label value to know what value belongs to which variable.
Give five examples of JavaScript primitives.
string, number, boolean, undefined, null.
What data type is returned by an arithmetic operation?
number
What is string concatenation?
joining strings together. Combination of two or more string values.
What purpose(s) does the+plus operator serve in JavaScript?
adds one value to another. Adding number values or concatenation.
What data type is returned by comparing two values (.===.etc)?
boolean
What does the += “plus-equals” operator do?
adds the value on the right, to the variable on the left, and then assigns that value back into the variable on the left.
What are objects used for?
objects group together a set of variables and functions to create a model of something. Allows us to store data together. Create collection of stuff.
What are object properties?
Individual data stored in object.
Describe object literal notation.
the object is the curly braces and their contents. The object is stored in a variable. Separate each property from its value using a colon. Separate each property and method with a comma.
How do you remove a property from an object?
to delete a property, use the delete keyword followed by the object name and property name.
What are the two ways to get or update the value of a property?
using the dot notation or the square brace.
What are arrays used for?
when working with a list or a set of values that are related to each other.
Describe array literal notation.
use var keyword followed by the name of array. Values are assigned to the array inside a pair of square brackets, and each value is separated by a comma.
How are arrays different from “plain” objects?
plain objects have property value pair, arrays just have values.
What number represents the first index of an array?
0
What is thelengthproperty of an array?
property to find out how many items are in an array
How do you calculate the last index of an array?
array[array.length - 1]
What is a function in Javascript?
Functions allow you to package up code for use later in your program.
Special type of object that can be called.
Set of reusable code that can be used in the future.
Describe the parts of a function definition.
the function keyword, an optional name, zero or more parameters, a code block, an optional return statement.
Describe the parts of a function call.
the name of the function, parenthesis with optional parameters.
When comparing them side-by-side, what are the differences between a functioncalland a functiondefinition?
the function keyword is only for definition.
Function call will have arguments. Definition always features a code block that needs to be executed.
Function call will not have curly braces.
What is the difference between aparameterand anargument?
functions are called with () parentheses and passed zero or more arguments.
Parameter is for function definition.
Argument is for calling functions with specific values.
why are function parameters useful?
passes on additional information to a function. Can make functions usable and data more dynamic.
What two effects does a return statement have on the behavior of a function?
causes the function to produce a value.
Exits the function; no code after the return statement is executed.
Why do we log things to the console?
to check the console output to see if your code is working correctly.
What is a method?
a function which is a property of an object.
How is a method different from any other function?
Method is a function on an object. A function can be called directly by it name. A method consists of a code that can be called by the name of its object and its method name using dot notation or square bracket notation.
How do you remove the last element from an array?
using the pop method on the nave of the variable.
How do you round a number down to the nearest integer?
using floor method of the math object with optional arguments.
How do you generate a random number?
using the random method on the math object and that expression being argument of the floor method of the math object.
How do you delete an element from an array?
using the splice method.
How do you append an element to an array?
using push and unshift methods.
How do you break a string up into an array?
using split method
Do string methods change the original string? How would you check if you weren’t sure?
no. you can try running string methods on variable and then console log the original variable to see if it is changed.
Roughly how many string methods are there according to the MDN Web docs?
about 50. There are a lot because strings are important.