Javascript Flashcards
What is a console?
The console is a panel that displays important messages, like errors, for developers. If we want to see things appear on our screen, we can print, or log, to our console directly.
In JavaScript, the console keyword refers to an object, a collection of data and actions, that we can use in our code.
console.log()
When we write console.log() what we put inside the parentheses will get printed, or logged, to the console. This is important so we can see the work that we’re doing.
The console.log() method outputs a message to the web console. The message may be a single string (with optional substitution values), or it may be any one or more JavaScript objects.
What are the two types of code comments in Javascript?
A single line comment and a multi-line comment
How do you write a single line comment?
// + comment
Note: You can also write a single line comment after a line of code.
How do you write a multi-line comment?
/* to begin the comment, and / to end the comment.
Note: you can also use this syntax to comment something out in the middle of a line of code.
Ex: console.log(/IGNORED!*/ 5); // Still just prints 5
When is it a good time to use multi-line comments?
When preventing a block of code from running.
What are data types? How many fundamental data types are there?
Data types are the classifications we give to the different kinds of data that we use in programming. There are 7 fundamental data types.
What are the seven different fundamental data types?
Number, string, boolean, null, undefined, symbol, and object.
What is a string data type?
Any grouping of characters on your keyboard (letters, numbers, spaces, symbols, etc.) surrounded by single quotes: ‘ … ‘ or double quotes “ … “
What is a boolean data type?
A data type that only has two possible values- true or false. You can think of it as answers to a “yes” or “no” question.
What is a null data type?
This data type represents the intentional absence of a value, and is represented by the keyword null
What is an undefined data type?
Uses the keyword undefined (without quotes) and means that a given value does not exist. It represents the absence of a value like null but is used differently.
What is an object data type?
Collections of related data.
What are literals in JS?
Literals represent values in JavaScript. These are fixed values—not variables—that you literally provide in your script.
What are identifiers in JS?
Identifiers are JavaScript names. They are used to name variables and keywords, and functions.
What are the rules for identifiers in JS?
The rules for legal names are the same in most programming languages. A JavaScript name must begin with:
A letter (A-Z or a-z)
A dollar sign ($)
Or an underscore (_)
Subsequent characters may be letters, digits, underscores, or dollar signs.
What are expressions?
An expression is a single unit of JavaScript code that the JavaScript engine can evaluate, and return a value.
An expression can be a literal, like a string or a number. It can also be an identifier that points to a variable.
Name three types of simple expressions in JS.
Arithmetic expressions,
String expressions,
Logical expressions.
Explain arithmetic expressions
Arithmetic expressions are expressions that take a variable and an operator (more on operators soon), and result in a number:
1 / 2
i++
i -= 2
i * 2
Explain logical expressions
Logical expressions make use of logical operators and resolve to a boolean value:
a && b
a || b
!a
Explain string expressions
String expressions are expressions that result in a string:
‘A ‘ + ‘string’
What is an operator?
An operator is a character that performs a task in our code.
What is the keyboard symbol for the multiply operator?
- Ex: 7 * 3 = 21
What is the keyboard symbol for the division operator?
/
Ex: 9/3 = 3