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:
- Download/install any web browser of your choice, or you can use the default browser on your PC.
- Right-click on any webpage,
- Click Inspect on the drop-down menu that pops up,
- Select the Console tab
In the console tab, type:
alert('Hello there!');
This command pops up a browser alert. JS just ran your instruction.
Now try:
console.log('Logging to the console');
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
JavaScript Order of Operations
JS follows PEMDAS rules:
1 + 1 * 3 // 4
(1 + 1) * 3 // 6
Beware of Decimal Errors In JavaScript (Floating Point Math)
0.1 + 0.2 // 0.30000000000000004
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)
JavaScript Math.round method snippet
Use Math.round()
for accurate totals:
Math.round(2.7) // 3
Math.round(2.3) // 2
You can round tax or totals like this:
Math.round((2095 + 799) * 0.1) / 100 // $2.89 tax rounded
Variables In JavaScript: Storing Values
Use variables to store and reuse data.
name = Dumebi's tutorial
console.log(name)
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
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
, notitem_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`
Concatenation in JavaScript
starterText = "The price is "
price = "$15"
endText = starterText + price
console.log(endText)
// The price is $15
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
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
A statement performs an action:
let total = 3 + 4;
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)
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');
}
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'));
You can pass data (arguments) into them and return a result.
function greet(name = 'Chris') {
return `Hello, ${name}!`;
}
console.log(greet());
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>
JavaScript:
document.getElementById('main-heading').textContent = 'Updated with JS!';
Create Elements on the Fly
const newElement = document.createElement('p');
newElement.textContent = 'I was added with JavaScript';
document.body.appendChild(newElement);
DOM Events in JavaScript: Listen to User Actions
<button id="clickMe">Click Me</button>
document.getElementById('clickMe').addEventListener('click', function() {
alert('Button was clicked!');
});
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}`);
Let’s connect it to the DOM:
<button onclick="calculateCart()">Calculate</button>
<p id="result"></p>
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}`;
}
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)
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?
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
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...
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!
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.
Yes, indeed. I agree. BTW, I think that you should absolutely share your story.
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.
Hmmm. A dictionary for coders? 🤔 Sounds like a brilliant idea, honestly. It'd help!
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?
You're right. Thanks so much for the idea. I'd actually work on it.
After your Javascript journey, see JurisJS , you will love it :-)
Yess. Totally.
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!
Thank you so much!
@dumebii do you think learning js again was a good idea? If yes how ??
I think so, yeah. Because the Web is still built on javascript. I don't think javascript developers will be out of demand soon.
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.
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.
It's good to review from the ground.
Thank you!
Some comments may only be visible to logged-in visitors. Sign in to view all comments.