Introduction to JS Flashcards
Six Data Types that are primitives:
Boolean. Null. Undefined. Number. String. Symbol (new in ECMAScript 6)
Interpolate values into a string in ES6
Use backticks (`) and ${variable}
Unset variables store the primitive data type as
undefined
Review Types and Operators
Four essential data types in JavaScript include strings, numbers, booleans, and null.
Data is printed, or logged, to the console with console.log().
Four built-in mathematical operators include +, -, , and /.
JavaScript associates certain properties with different data types.
JavaScript has built-in methods for different data types.
Libraries are collections of methods that can be called without an instance.
You can write single-line comments with // and multi-line comments between / and */.
Review Variables
Variables hold reusable data in a program.
JavaScript will throw an error if you try to reassign const variables.
You can reassign variables that you create with the let keyword.
Unset variables store the primitive data type undefined.
Mathematical assignment operators make it easy to calculate a new value and assign it to the same variable.
The + operator is used to interpolate (combine) multiple strings.
In JavaScript ES6, backticks (`) and ${} are used to interpolate values into a string.
Round up/down a decimal number
Math.ceil(x)
Math.floor(x)
prompt is a JavaScript function that will generate a pop-up window that asks the user for input, then it will assign their input to a variable.
const askTime = prompt(‘What’s the time?’);
What is the correct way to declare a variable that you can change?
let myName = ‘Sloan’;
const myName = ‘Sloan’;
variable myName = ‘Sloan’;
let myName: ‘Sloan’;
let myName = ‘Sloan’;
Which of the following lines of code capitalizes every letter in the string 'codecademy'
.
‘codecademy’.toCaps();
‘codecademy’.toUpperCase;
‘codecademy’.toUpperCase();
‘codecademy’.touppercase();
‘codecademy’.toUpperCase();
toUpperCase() is a built-in method, so it can be appended to the string.
Which of the following lines of code logs the length of the string ‘Hello World’?
Which of the following lines of code logs the length of the string 'Hello World'
?
console. log(‘Hello World!’.length)
console. log(length(‘Hello World!’))
console. log(‘Hello World!’.length())
console.log(‘Hello World!’.length)
length doesn’t need parentheses after it because it’s an attribute, not a method.
What is string interpolation?
When you change a variable’s value.
When you assign a string to a variable.
When you insert a string into a string.
When you insert the value of a variable into a string.
When you insert the value of a variable into a string.
Which of the following code snippets would cause an error?
const foodOne = 'chicken'; const foodTwo = 'sushi';
let food = 'chicken'; let drink = 'seltzer';
let food = 'chicken'; food = 'sushi';
const food = 'chicken'; food = 'sushi';
const food = 'chicken'; food = 'sushi'; Nice Job! const variables cannot be changed after they're created.
What is the correct way to generate a random number?
Number.random()
math. Random()
math. random()
Math.random()
Math.random()
This is the correct syntax.
Which of the following is the correct way to log a string to the console?
console. log{‘Hello World’};
console. log(Hello world);
consolelog(‘Hello world’);
console.log(‘Hello world’);
console.log(‘Hello world’);
What two values are considered boolean types?
truthy falsy
true false
‘true’ ‘false’
TRUE FALSE
true false