JS Basics Flashcards
What is a variable?
A variable is a way to store, change and use data.
“Named storage” for data
True or False when declaring multiple variables it is best practice to declare them on separate lines?
True
name: ‘Boba’;
This statement is an example of what?
A string literal
let age: 903;
This statement is an example of what?
A number literal
List some Data Types
String Boolean Number undefined Null Object
A ______ is a set of statements that calculates and returns a value or performs a task.
Function
What are we doing when we initialize a variable?
Assigning value to the variable
let listItem; is a _______, and listitem = 2; is a ______
let listItem; is a declaration and listItem = 2; is an assignment.
let puppies = 10;
puppies++;
console.log(puppies);
What are we doing to ‘puppies’ by using ++? What will the console log return?
Incrementing the number, adding one to it.
The console.log will return “11”
let droppedIceCreamCones = 150;
droppedIceCreamCones–;
console.log(droppedIceCreamCones);
What are we doing to ‘droppedIceCreamCones’ by using –? What will it return?
Decrementing it, taking one away
The console.log will return “149”
All integers is JS are ______ ______ numbers
Floating Point Numbers
What is another way to express:
b = 9 + b;
b += 9;
Plus-equals operator
What is another way to express:
a = a - 6;
a -= 6;
What is another way to express:
c = c * 10;
c *= 10;
What is another way to express:
a = a / 12 ;
a /= 12;
let myFavoriteThings = 'Gaming\nKnitting\nCoding'; console.log(myFavoriteThings)
What does the ‘\n’ an example of, and what does it do?
<p>'\n' is an example of a <i>string escape sequence</i> and will start the section of the string following it on a new line. </p>
So for this example: console.log(myFavoriteThings) will return "Gaming Knitting Coding" < -- each on their own line.
const fullName = 'AdaLovelace'; const lastLetterOfName = fullName[fullName.length - 1]; console.log(lastLetterofName)
What is this statement doing, and what will the return be?
This statement is finding the last index in the string by taking one away from the total length of the variable. Because JS starts counting at 0, taking one will dictate the last character.
It will return “e.”
How do we find out the length of a string?
Tip: This is a method
<p>By using the <b>.length</b> method</p>
Ex: let firstNameLength = 0; const firstName = 'Bartholomew'; firstNameLength = firstName.length; console.log(firstNameLength)
Will return: 11
const name = "Einstein"; let fourthLetterOfName = name[_]; console.log(fourthLetterOfName)
What would we put into the square brackets to find the fourth index in the string (i.e. the fourth letter of Einstein’s name)?
Tip: Remember JS starts counting at 0!
3
What is an array?
An array is an object that allows us to group and store data as a single variable.
It contains multiple values, that can be of mixed data types, and can even be other arrays or objects.