Basic JavaScript Flashcards

1
Q

Declare variables of type number, string, boolean, and undefined. (Not constants)

A

let someNum = 42;

let username = “playerOne”;

let isThisBool = true;

let iDunno = undefined;

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

Declare a constant of type string for username.

A

const username = “playerOne”;

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

Declare two numbers variables on the same line.

A

let numOne = 41, numTwo = 42;

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

A single line comment

A

// Single line of comment code

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

Multiple line comment

A

/* Multi
Line
Comment */

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

Increment and decrement a number variable by one.

A

someNumber++;
someNumber–;

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

Print a string to the browser console.

A

console.log(“Some String”);

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

Access a specific character from a string.

A

someString = “All these words:;

someCharacter = someString[0]; //First character

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

Basic conditional statement: if num is greater than 0, print a message to the console, else print another message.

A

if (num > 0) {
console.log(“Greater than zero”);
} else if (num =< 0) {
console.log(“NOT Greater than zero”);
}

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

Check if numOne and numTwo are STRICTLY equal.

A

if (numOne === numTwo){
console.log(“Yeah, it is”);
}

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

JavaScript syntax for AND, OR, Not Equal

A

&& (true && false)
|| (true || false)
! true

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

Switch (case) statement to set the “creator” variable based on the value of the “os” variable.

A

let creator;
switch (os) {
case “linux”:
creator = “Linus Torvalds”;
break;
case “windows”:
creator = “Bill Gates”;
break;
case “mac”:
creator = “Steve”;
break;
default:
creator = “Unknown”;
break;
}

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

Using a Ternary operator, set a variable’s value based on a condition.

A

const price = isMember ? “$2.00” : “$10.00”;

*After the question mark it the True value followed by the False value.

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

Using Nullish Coalescence, check for a name variable to be null, set a value accordingly.

A

let myName = null;
someName = myName ?? “Anonymous”;

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

Create a basic function that multiplies two numbers.

A

function multiplyTwoNums(numOne, numTwo){
let multi = numOne * numTwo;
return multi;
}

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

Anonymous function

A

// using an anonymous function
conversions(
function (a) {
return a + a;
},
1,
2,
3,
);
// 2 4 6

17
Q

Define an immediately invoked function expression (IIFE) that declares a variable of result equal to the sum of a + b.

A

const result = (function (a, b) { return a + b; })(1, 2);

console.log(result); // 3