I finished reading Love on the Brain. It was an interesting read. It started slow but picked up. It’s one of those reads when you want something fun and not serious.
Right now, I’m reading Stephen King’s Fairy Tale. This book captures your interest in the first few pages but goes so slowly. It really builds up slowly. I’m almost 200 pages in, and nothing really has happened yet. Yet you keep reading because you want to know what will happen! I can’t even say what this book is about yet cause I haven’t gotten to the main plot yet. I’m sure the whole book doesn’t revolve around a 17-year-old boy helping out an old man who broke his leg. And he already foreshadowed some events to come.
Alex is home today. They had no school. For what reason? I didn’t ask him. I just asked him, and he said he doesn’t know why… just that there is no school. Weird. I doubt it has to do with Easter.
Alexis has received her shoes at the college. I’m so happy cause the shoes that she has been wearing have a hole in them. I didn’t even know till I saw them over Spring Break. Why don’t these kids ever tell us these things? It’s not like we can’t get them a pair of shoes!
Chris has a test and may not be coming home this weekend. That sucks. Karissa has been working all day, so I just had to bug her a few times so she’d take a break.
I have so many JavaScript notes. Not to be confused with Java, JavaScript allows you to do more dynamic things to a webpage. Coding JavaScript seems simple enough right now cause I just started. I wonder how complex this language can get. Sorry these notes are so long. There are a lot more things to learn from this language.
—————————————————————————–
In computer science, data is anything meaningful to the computer. JavaScript provides eight different data types: undefined, null, boolean, string, symbol, bigint, number, and object.
For example, computers distinguish between numbers, such as the number 12, and strings, such as “12”, “dog”, or “123 cats”, which are collections of characters. Computers can perform mathematical operations on a number but not on a string.
Variables allow computers to store and manipulate data dynamically. They do this by using a “label” to point to the data rather than using the data itself. Any of the eight data types may be stored in a variable.
Variables are similar to the x and y variables you use in mathematics, which means they’re a simple name to represent the data we want to refer to. Computer variables differ from mathematical ones in that they can store different values simultaneously.
We tell JavaScript to create or declare a variable by putting the keyword var in front of it, like so:
var ourName;
Creates a variable called ourName. In JavaScript, we end statements with semicolons. Variable names can be made up of numbers, letters, and $ or _ but may not contain spaces or start with a number.
In JavaScript, you can store a value in a variable with the assignment operator (=).
myVariable = 5;
This assigns the Number value 5 to myVariable.
If there are any calculations to the right of the = operator, those are performed before the value is assigned to the variable on the left of the operator.
var myVar; myVar = 5;
First, this code creates a variable named myVar. Then, the code assigns 5 to myVar. Now, if myVar appears again in the code, the program will treat it as if it is 5.
After a value is assigned to a variable using the assignment operator, you can assign the value of that variable to another variable using the assignment operator.
var myVar; myVar = 5; var myNum; myNum = myVar;
The above declares a myVar variable with no value, then assigns it the value 5. Next, a variable named myNum is declared with no value. Then, the contents of myVar (which is 5) are assigned to the variable myNum. Now, myNum also has the value of 5.
Initializing a variable to an initial value in the same line as it is declared is common.
var myVar = 0;
Creates a new variable called myVar and assigns it an initial value of 0.
But you can also declare a string variable like this:
var myName = "your name";
“your name” is called a string literal. A string literal, or string, is a series of zero or more characters enclosed in single or double quotes.
When JavaScript variables are declared, they have an initial value of undefined. If you do a mathematical operation on an undefined variable your result will be NaN, which means “Not a Number”. If you concatenate a string with an undefined variable, you will get a string of undefined.
In JavaScript all variables and function names are case-sensitive. This means that capitalization matters.
MYVAR is not the same as MyVar nor myvar. It is possible to have multiple distinct variables with the same name but different casing.
Var can be overridden easily. So unlike var, when you use let, a variable with the same name can only be declared once.
let camper = "Tommy";
The keyword let is not the only new way to declare variables. In ES6, you can also declare variables using the const keyword.
const has all the features that let has, with the added bonus that variables declared using const are read-only. They are a constant value, which means that once a variable is assigned with const, it cannot be reassigned
const FAV_PET = "Cats";
You can easily increment or add one to a variable with the ++ operator.
i++;
You can easily decrement or decrease a variable by one with the — operator.
i--;
In programming, assignments are commonly used to modify a variable’s contents. Remember that everything to the right of the equals sign is evaluated first, so we can say:
myVar = myVar + 5;
One such operator is the += operator.
let myVar = 1; myVar += 5; console.log(myVar);
When you are defining a string you must start and end with a single or double quote. What happens when you need a literal quote: ” or ‘ inside of your string?
In JavaScript, you can escape a quote from considering it as an end of string quote by placing a backslash (\) in front of the quote.
const sampleStr = "Alan said, \"Peter is learning JavaScript\".";