Javascript Flashcards

1
Q

How would you create a .js file named Digital Nomad from the terminal?

A

touch digital-nomad.js

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

How would you run a js file named digital-nomad.js from the terminal?

A

node digital-nomad.js

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

What is the difference between shell REPL and the node REPL?

A

The shell REPL executes system commands, while the node REPL executes JavaScript. You can’t use the shell to execute JavaScript, and you can’t use node to execute system commands.

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

How would you write a comment in Javascript code?

A

// Comment goes here

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

What are two ways we would name a constant in JavaScript?

A

CamelCase (PascalCase) or ALL_CAPS_LIKE_THIS

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

In JavaScript, there are seven fundamental data types: what are they?

A

Number, String, Boolean, Null, Undefined, Symbol, Object

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

Explain the Number Datatype:

A

Any number, including numbers with decimals: 4, 8, 1516, 23.42.

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

Explain the String Datatype:

A

Any grouping of characters on your keyboard (letters, numbers, spaces, symbols, etc.) surrounded by single quotes: ‘ … ‘ or double quotes “ … “. Though we prefer single quotes. Some people like to think of string as a fancy word for text.

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

Explain the Boolean Datatype:

A

This data type only has two possible values— either true or false (without quotes). It’s helpful to think of booleans as on and off switches or as the answers to a “yes” or “no” question.

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

Explain the Null Datatype:

A

This data type represents the intentional absence of a value, and is represented by the keyword null (without quotes).

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

Explain the Undefined Datatype:

A

This data type is denoted by the keyword undefined (without quotes). It also represents the absence of a value though it has a different use than null.

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

Explain the Symbol Datatype:

A

A newer feature to the language, symbols are unique identifiers, useful in more complex coding.

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

Explain the Object Datatype:

A

Collections of related data.

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

What is a method? & Give an example

A

A Method is an action we can perform. Example: E.g. ‘example string’.methodName().

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

Say you have this variable let nomad = ‘Digital Nomad’; How would you do string interpolation.

A

console.log(My name is Daniel and I am a ${nomad}) we have to use backticks

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

Dog Years

Dogs mature at a faster rate than human beings. We often say a dog’s age can be calculated in “dog years” to account for their growth compared to a human of the same age. In some ways we could say, time moves quickly for dogs — 8 years in a human’s life equates to 45 years in a dog’s life. How old would you be if you were a dog?

Here’s how you convert your age from “human years” to “dog years”:

The first two years of a dog’s life count as 10.5 dog years each.
Each year following equates to 4 dog years.
Before you start doing the math in your head, let a computer take care of it! With your knowledge of math operators and variables, use JavaScript to convert your human age into dog years.

If you get stuck during this project or would like to see an experienced developer work through it, click “Get Unstuck“ to see a project walkthrough video.

Code the following in a code editor and create the file in ‘projects’ on your comp via the terminal and push it to git.

A
const myAge = 29; // My current age 
let earlyYears = 2; 
earlyYears *= 10.5 
let laterYears = myAge - 2;
laterYears *= 4;
let myAgeInDogYears = earlyYears + laterYears;
let myName = 'DANIEL'.toLowerCase();
console.log(`My name is ${myName}. I am ${myAge} years old in human years which is ${myAgeInDogYears} years old in dog years`);