Intro to JS Flashcards

1
Q

Declare two variables: admin and name.
Assign the value “John” to name.
Copy the value from name to admin.
Show the value of admin using alert (must output “John”).

A

let admin, name; // can declare two variables at once

name = “John”;

admin = name;

alert( admin ); // “John”

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

let

A

is a modern variable declaration

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

var

A

is an old-school variable declaration. Normally we don’t use it at all, but has subtle differences from let

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

const

A

is like let, but the value of the variable can’t be changed

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

What are these called? ``

A

Backticks

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

assignment operator

A

You can assign a value using the assignment operator =. For example:

let hello = “Hello”;

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

7 primitive data types in JavaScript

A

String
Null
Undefined
Boolean
Number
BigInt
Symbol

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

String

A

a string represents a sequence of characters and can be enclosed in either single (‘) or double (“) quotes.

Note that strings are immutable, which means once they are created, they cannot be changed.

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

array

A

An array is a non-primitive data type that can hold a series of values.

Arrays are denoted using square brackets ([]). Here is an example of a variable with the value of an empty array:

let array = [];

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

Primitive Data Type

A

Primitive data types like strings and numbers can only hold one value at a time.

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

Non-Primitive Data Type

A

Non-primitive data types differ from primitive data types in that they can hold more complex data.

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

Declare a variable

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

Index

A

You can access the values inside an array using the index of the value. An index is a number representing the position of the value in the array, starting from 0 for the first value.

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

How would you console log the first item in an array?

A

console.log(arrayName[0]);

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

Mutable Arrays

A

Arrays are special in that they are considered mutable. This means you can change the value at an index directly.

For example, this code would assign the number 25 to the second element in the array:

let array = [1, 2, 3];
array[1] = 25;

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

Use the .length array to get the last value of an array

A

array[array.length - 1]

17
Q

Method

A

A method in JavaScript is a function that’s associated with certain values or objects. An example you’ve already encountered is the .log() method, which is part of the console object.

18
Q

Array .push()

A

This allows you to “push” a value to the end of an array.
arrayName.push(12);

19
Q

Array .pop()

A

It removes the last element from an array and returns that element
popped = rows.pop();

20
Q

” “ or ‘ ‘

A

Generally, it doesn’t matter, but you want to be consistent throughout the build

21
Q

Const vs. Let

A

The let keyword allows a variable to be reassigned. This means you could change character later to be a completely different value.

First, a const variable cannot be reassigned like a let variable. This code would throw an error:

const firstName = “Naomi”;
firstName = “Jessica”;

A const variable also cannot be uninitialized. This code would throw an error:

const firstName;

22
Q

Iterator

A

The iterator is a variable you can declare specifically in your for loop to control how the loop iterates or goes through your logic.

It is a common convention to use i as your iterator variable in a loop.

23
Q

for loop syntax

A

for (let i = 0; i < count; i = i + 1) {
}

24
Q

concatenation

A
25
Q
A