JavaScript Flashcards
JS-primitives-and-variables
What is the purpose of variables?
= To store data/information that needs to do its job, and give that job a keyword(name), so that it can be used later on.
JS-primitives-and-variables
How do you declare a variable?
= var keyword, declare variable name, followed by semicolon
ex. var coding;
JS-primitives-and-variables
How do you initialize (assign a value to) a variable?
use assignment operator ( = ), and give variable a value, followed by semicolon. ( ex. quantity = 3;)
JS-primitives-and-variables
What characters are allowed in variable names?
= Letter, $ sign, or (_) underscore.
= Cannot start with a number. (but can have number in var names)
= Do not use dash (-) or a period (.)
= Cannot use keywords or reserved keywords (such as var, let, const, etc)
= Use camel case (ex. firstName)
= letters(upper or lowercase), numbers(not start with the numbers), and $ sign
JS-primitive-and-variables
What does it mean to say that variable names are “case sensitive”?
= “Score” and “score” will be treated as different variable names.
= Computers treat uppercase and lowercase as they have no relationship.
JS-primitives-and-variables
What is the purpose of a string?
= To work with any kinds of texts
= Store or manipulate text.
JS-primitives-and-variables
What is the purpose of a number?
= To work with numeric data types
= For math: calculate, holding numeric values
JS-primitives-and-variables
What is the purpose of a boolean?
= Give a value of true or false. Script to run either or options
= Binary logic: on/off, true/false, yes/no
JS-primitives-and-variables
What does the = operator mean in JavaScript?
= it assigns a value to a variable.
JS-primitives-and-variables
How do you update the value of a variable?
=Set a new value using the assignment operator.
** Var const, let, keyword is not required for updating the value
JS-primitives-and-variables
What is the difference between null and undefined?
= Null: can only exist when assigned. Null cannot be created by js.(purposeful emptiness = we’re gonna fill it later, or just for a purpose.)
= Undefined: js tells when value is empty. Js creates undefined. Developers don’t assign undefined.
JS-primitives-and-variables
Why is it a good habit to include “labels” when you log values to the browser console?
= to help you debug easily by looking for a label.
A console log “label” is simply a short string that describes the variable or value being logged.
= To easily find where the problem is happening.
JS-primitives-and-variables
Give five examples of JavaScript primitives.
= Sting = Number = Boolean = Null = Undefined
JS-operators-and-expressions
What data type is returned by an arithmetic operation?
=Numeric value (number)
JS-operators-and-expressions
What is string concatenation?
= Connecting strings, variables, or functions to log in a single line
= Addition for strings to variable.
= strings are immutable (cannot be edited) after created.
= Concatenation makes a new string, not changing the string.
JS-operators-and-expressions What purpose(s) does the + plus operator serve in JavaScript?
= Addition of values(number, string, etc) to the existing variable’s value
= Concatenation of a string to a value.
JS-operators-and-expressions
What data type is returned by comparing two values (greater than sign, less than sign, === etc)?
= Boolean value: True or false
JS-operators-and-expression
What does the += “plus-equals” operator do?
= Adds whatever the value is on the right side of the operand.
= adds the value of the right operand to a variable and assigns the result to the variable.
a += b means a = a + b
JS-objects
What are objects used for?
= Grouping/storing multiple variables and functions
= Multiple data to work together.
JS-objects
What are object properties?
= Variable within a certain boundary.
=You have to state where they are coming from. Properties tend to be group with other stuff.
= Properties are the values associated with a JavaScript object.
= Properties can usually be changed, added, and deleted, but some are read only.
JS-objects
Describe object literal notation.
= object name , assignment operator (=), followed by opening curly brace ({)
= And some variables (called keys/properties) with values separated with colon (:), and closed with closing curly brace (}), and semicolon (;).
var person = { name: ‘John’, age: 30, eyeColor: ‘blue’};
JS-objects
How do you remove a property from an object?
=delete objectname.key
= delete operator (delete)
delete Employee.firstname;
JS-objects
What are the two ways to get or update the value of a property?
= use . notation or bracket notation, but using dot notation is preferred.
person.name = ‘David’
JS-arrays
What are arrays used for?
=Storing ordered/unordered lists