JavaScript Knowledge Flashcards
What is a value in JavaScript? Give me an example
Its basically a piece of data, the most fundamental unit of information for programming. For example: A person’s name, a person’s age or person’s job. Can be within strings as well. Includes number as well. ‘Jonas’ or “Jonas”. 12, 14, 23 and etc.
In a JavaScript environment, those chunks are called values. Though all values are made of bits, they play different roles. Every value has a type that determines its role. Some values are numbers, some values are pieces of text, some values are functions, and so on. To create a value, you must merely invoke its name.
What is a Variable in JavaScript? Give me an example.
A variable stores the data value that can be changed. For example imagine a Variable like being a box, a box that can hold some object.
let firstName = “Jonas”; (firstName is the variable)
What does Camel case mean in JavaScript? Give an example.
Camel case means whenever we have multiple words in a variable name, write the first letter of the word as lower case, and then the next word on the first letter will be uppercase. For example:
console.log(firstName); (firstName being in camel case)
What do Variables only contain?
Numbers, letters, _ or the $
A Value is either an _____ or a _____ value.
an Object or a Primitive value
How many Primitive Data Types are there? Name them all.
There are 7 Primitive Data Types. Number, String, Boolean, Undefined, Null, Symbol (ES2015) and BigInt (ES2020).
Define each Primitive Data Types. Number String Boolean Undefined Null Symbol BigInt
Number- Floating point numbers, used for decimals and integer.
String- Sequence of characters, Used for text.
Boolean- Logical type that can only be true or false, Used for taking decisions.
Undefined- Value taken by a variable that is not yet defined. (empty value)
Null- Also means ‘empty value’
Symbol (ES2015)- Value that is unique and cannot be changed.
Bigint- Larger intergers than the Number type can hold.
What is dynamic typing? What does it mean?
That we can easily change the type of value that is held by a variable.
What types of operators are there?
Mathematical, comparison, logical
What is “string concatenation” mean? give me an example.
String concatenation is joining strings together.
console.log(“Hi, “ + firstName);
What is an “Array”?
// Array const fruits = ["apples", "oranges", "pears", "bananas"]; const myArray = [21, "pear", [3, 7, 22], { objectsToo: true }];
Array: Used to store multiple values in a single variable. Similar to a list.
What is a “String Concatenation”
String concatenation is joining strings together.
console.log(“Hi, “ + firstName);
What is a Template Literal?
Template literals are a special type of string that make creating complex strings so much easier. Template literals are created by surrounding text between opening and closing backticks (``). Inside a template literal, you’re able to refer to variables or execute code by using ${}. Take a look at the following example:
console.log(10 + 25 = ${10 + 25}
) // => “10 + 25 = 35”
By wrapping the calculation 10 + 25 in the ${}, we are able to calculate the total right there inside of the string. We can also refer to specific variables in a template literal as well:
const firstName = 'Kyle'; const greeting = `Hi, ${firstName}!`; console.log(greeting); // => "Hi, Kyle!"
Exponentiation operator (**) and modulus (remainder) operator (%), describe each one.
-The exponentiation operator (**) raises the first number to the power of the second number. 2 ** 2 = 4 2 ** 3 = 8 2 ** 4 = 16 4 ** 4 = 256 -The modulus (remainder) operator (%) returns the remainder of dividing the first number by the second number. 4 % 2 = 0 4 % 3 = 1
4 % 5 = 4
In the first example, we get 0 because 2 divides evenly into 4, so there isn’t a remainder. In the second, we have a result of 1 since 3 goes into 4 one time and then leaves us with a remainer of 1.
What is an Assignment Operator?
to increase our value by more than 1 though? Luckily, there’s an operator for that as well! We call this an assignment operator.
let num = 5;
num += 10
console.log(num) // => 15