I have taken a few moments to write down my thoughts about Lesson 11 on Data Types and Variables to answer the following questions:
- What new skills have I learned?
- What has been easy?
- What has been difficult?
- How have I used the problem solving strategies from the first project to overcome challenges so far?
Refer to my lesson notes below:
You can also perform calculations with numbers pretty easily. Basically type out an expression the way you would type it in a calculator. Also, just like in mathematics, you can compare two numbers to see if one’s greater than, less than, or equal to the other. Comparisons between numbers will either evaluate to true or false.
// this is a single-line comment
“Hello,” + ” New York City”
Returns: “Hello, New York City”
With variables, you no longer need to work with one-time-use data. Storing the value of a string in a variable is like packing it away for later use.
var greeting = “Hello”;
Now, if you want to use “Hello” in a variety of sentences, you don’t need to duplicate “Hello” strings. You can just reuse the greeting variable.
Naming Conventions for Variables
When you create a variable, you write the name of the variable using camelCase (the first word is lowercase, and all following words are uppercase). Also try to use a variable name that accurately and succinctly describes what the data is about.
- var totalAfterTax = 53.03; // uses camelCase if the variable name is multiple words
- var tip = 8; // uses lowercase if the variable name is one word
To access an individual character, you can use the character’s location in the string, called its index. Just put the index of the character inside square brackets (starting with  as the first character) immediately after the string.
- \\ – \ (backslash)
- \” – ” (double quote)
- \’ – ‘ (single quote)
- \n – newline
- \t – tab
The last two characters listed above, newline \n and tab \t, are unique because they add additional whitespace to your Strings. A newline character will add a line break and a tab character will advance your line to the next tab stop.
Another way to work with strings is by comparing them. The comparison operators == and != can also be uses with strings. Also, when you compare strings, case matters.
NaN stands for “Not-A-Number” and it’s often returned indicating an error with number operations. For instance, if you wrote some code that performed a math calculation, and the calculation failed to produce a valid number, NaN might be returned.
Implicit type coercion
Examples of strongly typed programming language code:
- int count = 1;
- string name = “Julia”;
- double num = 1.2932;
- float price = 2.99;
- var count = 1;
- var name = “Julia”;
- var num = 1.2932;
- var price = 2.99;
Happy Coding and Blogging!