Welcome to Level up with JavaScript
In this blog series tutorial, you will be introduced to some of the basic JavaScript programming concepts.
This is geared toward beginners and anyone looking to refresh their knowledge.
To get started, here is an example of a basic JavaScript program called "Hello World".
function greetMe(yourName) {
alert("Hello " + yourName);
}
greetMe("Zach");
"Hello Zach"
Now that you have seen what JavaScript is and an example of how to write a simple program, let's level up!
Comments, Declaring Variables, Storing, Assigning, and Initializing Values
Comments
Comments are notes about your code for you or other developers.
JavaScript will ignore everything after a double forward slash for in-line, and between a forward slash + asterisk for multiline.
// This is an inline comment
/* This is a
multi-line comment */
Declaring Variables
Variables allow computers to store and use data.
JavaScript uses these eight data types: undefined, null, boolean, string, symbol, bigint, number, and object.
These variables must be declared by the "var", "let", or "const" keyword.
Variables can have numbers, letters, dollar signs, or underscores. They cannot contain spaces or start with numbers.
Semicolons are used at the end of statements. They are sometimes optional in JavaScript because of automatic semicolon insertion.
However, I would advise always including them until you are more experienced.
var level;
Storing Values
Values can be stored as a variable with the assignment operator (=).
In this example, I declare the variable "level" and set it to the value 1.
Now each time "level" appears in the code, the program will treat it as 1.
var level;
level = 1;
Assigning Values
Next, the assignment operator can be used to assign the same value from the previous variable to another variable.
With the below example, now JavaScript_level and level are both the same value of 1.
var level;
level = 1;
var JavaScript_level;
JavaScript_level = level;
Initializing Values
Initialize allows us to assign an initial value to a variable as it is declared.
This is done on the same line that the variable is created.
var level = 1;
Top comments (9)
Thanks for your article!
Is there a difference between this
and this
or is the completely equivalent?
Exactly what Alexander said. In addition let and var can be used. It is most common preactice now to use let and const though. I will be digging deeper into the different types later in the blog series. For now though, const is used to create a variable that can not be changed. Var can be changed anywhere. Let can be changed in the Block scope of the function.
Thanks!
They are different. For example, "functions" have a "this" pointer. Fat arrow functions try to find "this" in the scope.
I try to avoid "funtions" whenever I can.
Thank you!
Thank you for replying!
Have you tried this?
It's pretty handy 😉
Very nice article, for code highlights you can specify the language
Read More: markdownguide.org/extended-syntax/
Thank you!