Introduction to JS Flashcards Preview

JavaScript Basics > Introduction to JS > Flashcards

Flashcards in Introduction to JS Deck (18)
Loading flashcards...
1

Six Data Types that are primitives:

Boolean.
Null.
Undefined.
Number.
String.
Symbol (new in ECMAScript 6)

2

Interpolate values into a string in ES6

Use backticks (`) and ${variable}

3

Unset variables store the primitive data type as

undefined

4

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

5

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.

6

Round up/down a decimal number

Math.ceil(x)
Math.floor(x)

7

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?');

8

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

9

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.

10

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.

11

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.

12

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.

13

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.

14

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

15

What two values are considered boolean types?

truthy falsy

true false

'true' 'false'

TRUE FALSE

true false

16

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

let myName = 'Sloan';

17

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;

x *= 2;

18

Mathematical Operators

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