Hey everyone!
In today’s JavaScript class, I learned some very interesting and fun topics that form the core of how JavaScript handles calculations, values, and operations. Here's a summary of what I learned today
Concatenation in JavaScript
Concatenation means joining two or more strings.
In JavaScript, if you use + between a string and a number, it will combine them as a string.
console.log("10" + 5); // Output: "105"
Dynamic Typing
JavaScript is a dynamically typed language, which means:
- You don’t need to declare the data type of a variable.
- The type can change automatically based on the value assigned.
let value = "10" + 5; // value is now a string: "105"
JavaScript Operators
We learned about different types of operators, especially:
NaN – Not a Number
NaN stands for Not a Number. It shows up when a calculation doesn’t result in a valid number.
let result = "hello" * 5;
console.log(result); // NaN
Pre & Post Increment/Decrement
Post-Increment (x++)
The current value is used first, then incremented.
let x = 5;
console.log(x++); // Output: 5
console.log(x); // Output: 6
Pre-Increment (++x)
The value is increased first, then used.
let x = 5;
console.log(++x); // Output: 6
Post-Decrement (x--)
let y = 10;
console.log(y--); // Output: 10
console.log(y); // Output: 9
Pre-Decrement (--y)
let y = 10;
console.log(--y); // Output: 9
Summary
Here's what I learned today:
- Concatenation joins strings and numbers.
- JavaScript uses dynamic typing.
- NaN means Not a Number.
- Arithmetic operators perform basic math.
- Pre/Post Increment & Decrement help us increase or decrease values easily.
Top comments (0)