DEV Community

Cover image for Level Up with JavaScript
DevCronin
DevCronin

Posted on • Updated on

Level Up with JavaScript

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"

Enter fullscreen mode Exit fullscreen mode

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 */

Enter fullscreen mode Exit fullscreen mode

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;

Enter fullscreen mode Exit fullscreen mode

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;

Enter fullscreen mode Exit fullscreen mode

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;

Enter fullscreen mode Exit fullscreen mode

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;

Enter fullscreen mode Exit fullscreen mode

Thank you for reading my blog! This is the first of my series on JavaScript so if you would like to read more, please follow!

See the Next Level Here

Support and Buy me a Coffee

Top comments (9)

Collapse
 
loicboset profile image
Loïc Boset

Thanks for your article!

Is there a difference between this

function greetMe(yourName) { 
    alert("Hello " + yourName); 
} 
Enter fullscreen mode Exit fullscreen mode

and this

const greetMe = (yourName) => alert("Hello " + yourName)
Enter fullscreen mode Exit fullscreen mode

or is the completely equivalent?

Collapse
 
devcronin profile image
DevCronin

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.

Collapse
 
loicboset profile image
Loïc Boset

Thanks!

Collapse
 
alexander89 profile image
Alexander Halemba • Edited

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.

Collapse
 
loicboset profile image
Loïc Boset

Thank you!

Collapse
 
devcronin profile image
DevCronin

Thank you for replying!

Collapse
 
pedro_dgcouto profile image
Pedro Couto • Edited

Have you tried this?

function greetMe(yourName) { 
    alert(`Hello ${yourName}`); 
} 
Enter fullscreen mode Exit fullscreen mode

It's pretty handy 😉

Collapse
 
grayhat profile image
Mwenda Harun Mbaabu • Edited

Very nice article, for code highlights you can specify the language

Read More: markdownguide.org/extended-syntax/

Collapse
 
devcronin profile image
DevCronin

Thank you!