Let’s get started with this recorded live session
Estimated reading and practice time: approx. 1 hour
Some notes regarding the
undefined: Can be thought of as a value used for
unintentionally missing values, for example declared variables with no values assigned to them:
let myEmptyVariable; /* In the next line we are accessing a variable, but forgot to assign a value to it */ console.log( myEmptyVariable ); // undefined
Remember, that the language specification states that:
undefinedis used when a variable has not been assigned a value
You will also find
undefined when trying to access Object properties that have not been created (more on this on the next lessons) and on Function parameters that have not been assigned a value (also, more on this later).
null: Can be used for intentionally missing values.
Here’s how the language specification describes null:
null represents the intentional absence of any object value
Variables are pointers to "storage containers" for data in your code. You can think of variables as something close to your contacts in your mobile phone. Each contact list entry contains a name, e.g. Mary. This is your variable name. And each contact list name (variable name) points to a place in the memory of your mobile phone that stores a telephone number or address, e.g. 6985252114.
|VARIABLE NAME||POINTER TO||DATA IN MEMORY|
|Mary||— Points to –>||6985252114|
|Ahmed||— Points to –>||6971234567|
In much the same way, variables in programming languages, are names that point to some memory location in which some kind of data is stored:
var someVariableName = "Just some text."; // The someVariableName, now points to a place in memory // where the "Just some text." data is stored and can be retrieved.
Tasks section where you can (must) practice all the concepts that you’ve learned.
The estimated reading and practice time for this material is approximately 2 hours.
Here is a list of the concepts you’ll be introduced to through this post:
The above tutorial mentioned this, but it’s important enough to note again:
varstatements. Don’t let it bother you! There’s nothing inherently wrong with
var, and in most cases
letbehave the same way. But sometimes the behavior of
varis not what you would expect. Just stick to
const) for now. The precise differences between
letwill be explained later. (Source: The Odin Project)
At this point, it is advised that you read the following article which will provide some insights on how to approach programming problems and challenges. How to think like a programmer — lessons in problem solving. You will go over this article again in one of the upcoming projects.
Save the HTML file in a folder, add the folder in a new
VSCode workspace and launch the web page in the browser using the
LiveServer VSCode extension. By right-clicking on the web page you can select
Inspect Element and be able to watch the output on the
Developer Tools console. The
console.log() command will display any value you place inside the parentheses in the browser’s console and this is a command you’ll be using on a daily basis.
Try to complete the following steps:
Basic Numeric Operations:
console.log(23 + 97)into your html file)
(4 + 6 + 9) / 77
let a = 10
9 * a
let b = 7 * a(returns undefined) and then
maxwith the value
max - 13
actual / max
percentagein the console and press enter you should see a value like
Create a variable named
balance and assign an amount to it. (Think of this as a bank deposit transaction)
Create a variable named
yearly_interest and set the value to
0.05. This amounts for a 5% interest rate on a yearly basis for a savings account.
balance after 2 years and also after 4 years.
Calculate Grade Average:
const studentA_history = 6; const studentA_math = 7; const studentA_geography = 5; const studentA_art = 8; const studentA_physics = 4; const studentA_chemistry = 7; const studentB_history = 4; const studentB_math = 9; const studentB_geography = 5; const studentB_art = 5; const studentB_physics = 6; const studentB_chemistry = 4;
const VAT = 24; // VAT Tax is set to 24% const smartphone = 300; // Net price const total = smartphone + ( smartphone * ( VAT / 100 ) ); // Total === net price + VAT
How about calculating a woman’s fertile window?
Blood alcohol content anyone?
Your instructor will share a link to the assignment repository. Work on your assignment and submit your Pull Request link in the Quiz below.