JavaScript was a doozy today. I’m still trying to understand what I learned today. So I have my notes. My brain is kind of fried at the moment. I don’t even think I actually learned the subjects today. parseInt() and conditional operators are confusing.
My car won’t be ready till tomorrow. They ordered the wrong part for my car. So the Bug should be ready by 10am tomorrow with new brakes.
I feel like it should be Friday. It feels like a Friday. Or maybe I just want it to be a Friday. Sunday we are going out to tea.. Winnie the Pooh theme! And then heading to a friend’s house for some gaming. I’m going to post this as is. I just don’t have that much to talk about right now.
JavaScript notes:
————————————–
The parseInt() function parses a string and returns an integer. Here’s an example:
const a = parseInt("007");
The above function converts the string 007 to the integer 7. If the first character in the string can’t be converted into a number, then it returns NaN.
The parseInt() function parses a string and returns an integer. It takes a second argument for the radix, which specifies the base of the number in the string. The radix can be an integer between 2 and 36.
The function call looks like:
parseInt(string, radix);
And here’s an example:
const a = parseInt("11", 2);
The radix variable says that 11 is in the binary system, or base 2. This example converts the string 11 to an integer 3.
The conditional operator, also called the ternary operator, can be used as a one line if-else expression.
The syntax is a ? b : c, where a is the condition, b is the code to run when the condition returns true, and c is the code to run when the condition returns false.
The following function uses an if/else statement to check a condition:
function findGreater(a, b) { if(a > b) { return "a is greater"; } else { return "b is greater or equal"; } }
This can be re-written using the conditional operator:
function findGreater(a, b) { return a > b ? "a is greater" : "b is greater or equal"; }