javascript-primitives-and-variables Flashcards
What is the purpose of variables?
to store information that can be used later
How do you declare a variable?
let {variable_name} = {information} , const or var
How do you initialize (assign a value to) a variable?
declare the variable ( let, const, var ) then the = sign then the information
What characters are allowed in variable names?
any combination of letter, digit, or symbols $ and _ , it cannot begin with a number.
What does it mean to say that variable names are “case sensitive”?
The capitalization of the variable name must match. If you create two variables with different capitalization you have created two separate variables.
What is the purpose of a string?
a string is used to store text that is in a human readable format
What is the purpose of a number?
a number is used to store a number that can be used for calculations
What is the purpose of a boolean?
a boolean is used to store the result of a condition. It has two options, true or false
What does the = operator mean in JavaScript?
it is used to assign a value to a variable
How do you update the value of a variable?
you can update by using the assigmnet operator ‘=’
What is the difference between null and undefined?
null is a value that represents the absence of an object. It is typically used to indicate that a variable does not refer to an object, or that a function does not return an object.
undefined is a value that indicates that a variable has not been assigned a value. If you try to access a variable that has not been declared or assigned a value, it will have the value undefined.
Why is it a good habit to include “labels” when you log values to the browser console?
Labels help to distignuish the values from eachother
Give five examples of JavaScript primitives.
In JavaScript, a primitive is a data type that is not an object and has no methods.
number: This data type represents numeric values, such as integers (e.g. 1, 2, 3) and floating-point numbers (e.g. 1.5, 2.3, 3.14).
string: This data type represents a sequence of characters, such as words, sentences, and paragraphs. Strings are enclosed in quotes (either single or double).
boolean: This data type has only two values: true and false. It is commonly used in conditional statements to test for certain conditions.
null: This data type has only one value: null. It represents the absence of an object.
undefined: This data type has only one value: undefined. It indicates that a variable has not been assigned a value.