DEV Community

Cover image for I Started Learning JavaScript Again—A Beginner-Friendly Guide to the Basics
Dumebi Okolo
Dumebi Okolo

Posted on

I Started Learning JavaScript Again—A Beginner-Friendly Guide to the Basics

You can tell from the title of this article that I am learning Javascript again from scratch and will build my way up to React and Node.Js.
You might be wondering why.
Well, I wrote an article for an organization recently, and this is part of the feedback I received: "... the repo is somewhat improved with the last update, but it is still not the best code quality."
Safe to say that I felt horrible. But it was a constructive review nonetheless. It made me look within, and I found that I have lost touch with a lot of my coding abilities.


I am on a journey to refresh myself with the basics, and I am taking you along with me!
You can think of this as a beginner-friendly tutorial, but it is also designed for people with pre-existing knowledge. It doesn't go too in-depth and just basically gives snippets with little explanations for those looking for a quick refresher.

  • I am learning with this video.

This article is part of a series I am starting.

In this tutorial, we’ll:

  • Understand what JavaScript is and why it’s powerful
  • Write and test our first JS code using the browser console
  • Explore data types like numbers and strings
  • Learn about variables, expressions, and statements
  • Dive into the Document Object Model (DOM)
  • Use logic and functions to build a simple shopping cart

Let’s get started.


What is JavaScript?

JavaScript (JS) is a programming language used to make websites dynamic.
It is good to remind yourself of the basics sometimes so that you don't abuse or underutilize the potential of JavaScript.
While HTML gives structure and CSS adds style, JavaScript makes things interactive — like dropdown menus, popups, calculators, games, and real-time feedback.

For this tutorial, we’re using Google Chrome and the DevTools Console — no extra software required.


Your First JavaScript Code (No Setup Required)

How to Open the JavaScript Browser Console:

  1. Download/install any web browser of your choice, or you can use the default browser on your PC.
  2. Right-click on any webpage,
  3. Click Inspect on the drop-down menu that pops up,
  4. Select the Console tab

In the console tab, type:

alert('Hello there!');
Enter fullscreen mode Exit fullscreen mode

This command pops up a browser alert. JS just ran your instruction.

a blank google webpage showing an alert from a console

Now try:

console.log('Logging to the console');
Enter fullscreen mode Exit fullscreen mode

This logs a message in the console, a very important tool for debugging.


Numbers and Operations In JavaScript

JS handles all basic math operations:

2 + 2          // 4 addition
10 - 3         // 7 subtraction
10 * 3         // 30 multiplication
10 / 2         // 5 divison
15 % 2         // 3 modulus
10^3           // 1000 exponential
Enter fullscreen mode Exit fullscreen mode

JavaScript Order of Operations

JS follows PEMDAS rules:

1 + 1 * 3        // 4
(1 + 1) * 3      // 6
Enter fullscreen mode Exit fullscreen mode

Beware of Decimal Errors In JavaScript (Floating Point Math)

0.1 + 0.2        // 0.30000000000000004
Enter fullscreen mode Exit fullscreen mode

Because of how computers handle decimal numbers, small inaccuracies can occur.

In that case, when calculating for money, use cents (a smaller currency).

(2095 + 799) / 100     // 28.94 (represent $20.95 + $7.99)
Enter fullscreen mode Exit fullscreen mode

JavaScript Math.round method snippet

Use Math.round() for accurate totals:

Math.round(2.7)      // 3
Math.round(2.3)      // 2
Enter fullscreen mode Exit fullscreen mode

You can round tax or totals like this:

Math.round((2095 + 799) * 0.1) / 100   // $2.89 tax rounded
Enter fullscreen mode Exit fullscreen mode

Variables In JavaScript: Storing Values

Use variables to store and reuse data.

name = Dumebi's tutorial
console.log(name)
Enter fullscreen mode Exit fullscreen mode

let and const in JavaScript

let quantity = 3;
quantity = quantity + 1;    // 4

const taxRate = 0.1;

// taxRate = 0.2; ❌ Error — const can’t be reassigned
Enter fullscreen mode Exit fullscreen mode

What the last comment is saying is that once a variable name is predicated with const, its value or content cannot be changed later on in the code.

Use const by default; switch to let if you need to reassign.

JavaScript Naming Conventions

  • Use camelCase: itemPrice, not item_price
  • Start with letters (not numbers or symbols)

Strings: Working with Text In JavaScript

A string is just text wrapped in quotes:

'hello'
"world"
`template`
Enter fullscreen mode Exit fullscreen mode

Concatenation in JavaScript

starterText = "The price is "
price = "$15"        
endText = starterText + price
console.log(endText)
// The price is $15
Enter fullscreen mode Exit fullscreen mode

Template Literals in JavaScript

We use backticks, the dollar sign, and curly braces ${} for template literals:

num1 = 5
num2 = 6
add = num1 + num2 
addt = "Total number is:" + `${add}`
console.log(addt)
// Total number is:11
Enter fullscreen mode Exit fullscreen mode

Template literals are used to concatenate two types if data in JavaScript. In DOM manipulation, it can also be used to add JavaScript to a DOM expression

Expressions vs. Statements In Javascript

An expression is a piece of code that produces a value:

3 + 4
Enter fullscreen mode Exit fullscreen mode

A statement performs an action:

let total = 3 + 4;
Enter fullscreen mode Exit fullscreen mode

Booleans & Comparison Operators In JavaScript

Booleans are either true or false. Useful in decision making:

true
false
5 > 3              // true
5 === 5            // true
'5' === 5          // false (strict equality)
Enter fullscreen mode Exit fullscreen mode

The last statement is false because the strict equality operator in JavaScript === is true when the values are exactly the same in vLalue and type. '5', although a figure is of a type string because it is enclosed in quotations. The 5 on the left hand side, howevevr is a figure of the type integer.

Use booleans in conditions with if blocks:

const age = 16;
if (age >= 18) {
  console.log('Adult');
} else {
  console.log('Minor');
}
Enter fullscreen mode Exit fullscreen mode

We will talk about conditional more indepth in the next article.


Functions In JavaScript: Reusable Code Blocks

Functions help you avoid repeating yourself:

function greet(name) {
  return `Hello, ${name}!`;
}

console.log(greet('Chris'));
Enter fullscreen mode Exit fullscreen mode

You can pass data (arguments) into them and return a result.

function greet(name = 'Chris') {
  return `Hello, ${name}!`;
}

console.log(greet());
Enter fullscreen mode Exit fullscreen mode

Introducing the DOM (Document Object Model) in JavaScript

The DOM is a live tree of all elements on a webpage. With DOM mnaipulations in JavaScript, you can:

  • Access HTML elements
  • Change their content
  • React to user actions

Example: Change a heading

HTML:

<h1 id="main-heading">Original</h1>
Enter fullscreen mode Exit fullscreen mode

JavaScript:

document.getElementById('main-heading').textContent = 'Updated with JS!';
Enter fullscreen mode Exit fullscreen mode

Create Elements on the Fly

const newElement = document.createElement('p');
newElement.textContent = 'I was added with JavaScript';
document.body.appendChild(newElement);
Enter fullscreen mode Exit fullscreen mode

DOM Events in JavaScript: Listen to User Actions

<button id="clickMe">Click Me</button>
Enter fullscreen mode Exit fullscreen mode
document.getElementById('clickMe').addEventListener('click', function() {
  alert('Button was clicked!');
});
Enter fullscreen mode Exit fullscreen mode

Remember that for this to work, the JavaScript file containing the code must have been added to the HTML file via a script tag at the head element.


JavaScript Beginner Project: Shopping Cart Calculator

const item1 = 2095; // in cents
const item2 = 799;
let total = item1 + item2;

let shipping = total <= 1000 ? 499 : 0;
const tax = Math.round(total * 0.1);

const finalAmount = total + shipping + tax;

console.log(`Final Total: $${finalAmount / 100}`);
Enter fullscreen mode Exit fullscreen mode

Let’s connect it to the DOM:

<button onclick="calculateCart()">Calculate</button>
<p id="result"></p>
Enter fullscreen mode Exit fullscreen mode
function calculateCart() {
  const item1 = 2095;
  const item2 = 799;
  const shipping = (item1 + item2 <= 1000) ? 499 : 0;
  const tax = Math.round((item1 + item2) * 0.1);
  const final = item1 + item2 + shipping + tax;

  document.getElementById('result').textContent = `Total: $${final / 100}`;
}
Enter fullscreen mode Exit fullscreen mode

Now when you click the button, it calculates and shows the total.


All the code in this article was written in the browser console.
In this first article, we covered:

  • Writing JS in the browser console
  • Numbers, strings, variables, expressions, and statements
  • Booleans, comparisons, and conditional logic
  • Functions to reuse code
  • DOM manipulation: changing elements, handling clicks

We even built a simple cart system using JavaScript and connected it to the webpage. Not bad for day one! I am excited for what is to come next. Hopefully, I can make this a weekly endeavor.

Thanks for learning with me. Let’s keep going!
Find me on Linkedin.

Top comments (20)

Collapse
 
dotallio profile image
Dotallio

Love how you turned feedback into motivation to relearn the basics, and the shopping cart example makes it instantly practical. Do you have specific topics lined up for the next article in your series?

Collapse
 
dumebii profile image
Dumebi Okolo

Yeah. I'm actually following the video as a guideline. Depending on how far I'm able to go in the video, I'd write about my progress.

Thank you xxx

Collapse
 
rickdelpo1 profile image
Rick Delpo

Hey there Dumebi and other readers. I really LOVE this practical guide on basic JavaScript. And also your other articles and how you really like to hold the beginners hands. You would make a very patient teacher. Check out my dev article below on how I approach plain JS without Node or external libraries, just using a browser and Notepad. I really furthered my career in Data Science by keeping it simple. Am retired after a 20 year run and now do volunteer work teaching students. This short article is part of an ebook I am writing on the topic of helping those feeling left behind.
dev.to/rickdelpo1/plain-javascript...

Collapse
 
dumebii profile image
Dumebi Okolo

Hi Rick, thank you so much for the compliment.
I have actually read your article before now. 😅
I think it's really super and touches heavily on some important things.
Great work you're doing!

Collapse
 
rickdelpo1 profile image
Rick Delpo • Edited

Don't underestimate the importance of JavaScript. My approach is both a learning and a teaching methodology where we include data in our toolbox of skills. I make the barriers to entry less burdensome for the frustrated beginner who is ready to give up. By including data in the mix it actually landed me a job at age 51 when I thought all was lost and now 20 years later I have a story to tell about it. Learning JavaScript WILL significantly broaden your skillset.

Thread Thread
 
dumebii profile image
Dumebi Okolo

Yes, indeed. I agree. BTW, I think that you should absolutely share your story.

Collapse
 
dimitrim profile image
Dimitri Mostrey

Yes, the basics. So often overlooked.

In general, I often struggle with the exact definition of words used. For example, a function in a class is called a method. As many of us, we learned by doing. Trying, failing, understand why, and trying again.

We didn't learn coding at school, college or university. It leads to confusion in some cases when reading a 'howto" or documentation. I missed the basics of the basics. Which make me uncertain in writing articles myself of things I learned along the way.

It would be helpful to have some kind of dictionary for coders. Pretty sure it exists somewhere but I couldn't find one.

Collapse
 
dumebii profile image
Dumebi Okolo

Hmmm. A dictionary for coders? 🤔 Sounds like a brilliant idea, honestly. It'd help!

Collapse
 
dimitrim profile image
Dimitri Mostrey • Edited

Good idea. Keep it simple, in this sense, languages have their own specific definitions but some definitions overlap them all. For example primitives. Sounds trivial. The article above is proof that refreshing the basics is not a bad idea at all. It could become your most visited and shared article as of yet. Who knows.

The idea comes from newly created (private) schools/classes teaching adults the basics of math and language. To the surprise of many, these courses are generally well attended. There is a need to go back to basics in our societies. So it seems. Why not?

Thread Thread
 
dumebii profile image
Dumebi Okolo

You're right. Thanks so much for the idea. I'd actually work on it.

Collapse
 
artydev profile image
artydev • Edited

After your Javascript journey, see JurisJS , you will love it :-)

Collapse
 
dumebii profile image
Dumebi Okolo

Yess. Totally.

Collapse
 
itxitpro_llc profile image
ITXITPro LLC

Nice guide, Dume! 👏 Your beginner-friendly walkthrough—covering everything from variables and functions to DOM manipulation—makes jumping back into JavaScript so smooth. Love the clear examples and practical tips. Perfect for anyone restarting their JS journey!

Collapse
 
dumebii profile image
Dumebi Okolo

Thank you so much!

Collapse
 
codsensei profile image
Krishna Agarwal

@dumebii do you think learning js again was a good idea? If yes how ??

Collapse
 
dumebii profile image
Dumebi Okolo

I think so, yeah. Because the Web is still built on javascript. I don't think javascript developers will be out of demand soon.

Collapse
 
jim_duse_41da0a4decea944d profile image
Jim Duse

I'm a mid level dev and I looove JS, but I wonder, if this is a good time to start learning code! With these AI models poppin up everywhere! I heard AI dev is the way to go now.

Collapse
 
dumebii profile image
Dumebi Okolo

If you don't have dev knowledge, vibe coding would be like crossing an ocean on a log. You need knowledge and understanding especially when it comes to debugging AI code.

Collapse
 
moikaturns profile image
Mark

It's good to review from the ground.

Collapse
 
dumebii profile image
Dumebi Okolo

Thank you!

Some comments may only be visible to logged-in visitors. Sign in to view all comments.