Introduction to JS Flashcards

1
Q

Six Data Types that are primitives:

A
Boolean.
Null.
Undefined.
Number.
String.
Symbol (new in ECMAScript 6)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Interpolate values into a string in ES6

A

Use backticks (`) and ${variable}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Unset variables store the primitive data type as

A

undefined

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Review Types and Operators

A

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 */.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Review Variables

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Round up/down a decimal number

A

Math.ceil(x)

Math.floor(x)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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.

A

const askTime = prompt(‘What’s the time?’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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’;

A

let myName = ‘Sloan’;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which of the following lines of code capitalizes every letter in the string 'codecademy'.

‘codecademy’.toCaps();

‘codecademy’.toUpperCase;

‘codecademy’.toUpperCase();

‘codecademy’.touppercase();

A

‘codecademy’.toUpperCase();

toUpperCase() is a built-in method, so it can be appended to the string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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())

A

console.log(‘Hello World!’.length)

length doesn’t need parentheses after it because it’s an attribute, not a method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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.

A

When you insert the value of a variable into a string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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';
A
const food = 'chicken';
food = 'sushi';
Nice Job! const variables cannot be changed after they're created.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the correct way to generate a random number?

Number.random()

math. Random()
math. random()

Math.random()

A

Math.random()

This is the correct syntax.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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’);

A

console.log(‘Hello world’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What two values are considered boolean types?

truthy falsy

true false

‘true’ ‘false’

TRUE FALSE

A

true false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the correct way to declare a variable that you can change?

const myName = ‘Sloan’;

let myName = ‘Sloan’;

let myName: ‘Sloan’;

variable myName = ‘Sloan’;

A

let myName = ‘Sloan’;

17
Q

Given the variable x is initially equal to five, which expression will reassign x to ten?

let x = 5;
----------------------------

x = x / 2

x -= 5;

x *= 2;

x = x + 10;

A

x *= 2;

18
Q

Mathematical Operators

A
let x = 4;
x += 2; // x equals 6
let y = 4;
y -= 2; // y equals 2
let z = 4;
z *= 2; // z equals 8
let r = 4;
r++; // r equals 5
let t = 4;
t--; // t equals 3