DEV Community

Harsh
Harsh

Posted on

Day-35 of Coding!

100DaysOfCode – Day 35

Today I started learning JavaScript through The Odin Project and got my first look at how it works in the browser.

  • Learned how to assign variables using let, const, and var.
  • Used alert() and console.log() to show output in the browser.
  • Realized that let is the modern way to declare variables — var still works but has older behavior.
  • JavaScript can only store numbers precisely up to about 15–16 digits because of IEEE 754 limitations.
  • For bigger numbers, you need to use BigInt to avoid precision errors.

There are both variables and constants in JavaScript — it’s not like Python at all! 😅

Top comments (6)

Collapse
 
csm18 profile image
csm

One of the big reasons for using let over var is:
let is block scoped while var is not!
You can do a quick search on what is block scope and how it effects(an important topic)!

Collapse
 
harshvdev profile image
Harsh

I just checked. It's complicated... Doesn't seem as easy as Python.

Collapse
 
csm18 profile image
csm

with var:
a) if you declare a variable outside of a function, that is global scope and is accessible anywhere in that file.
b) if you declare it inside a function, it is function scoped, that means accessible anywhere inside that function.
Here, it has downside.If you declare a variable inside an if statement of a function,then it is accessible outside of that if statement!

if(true){
    var name = "ravi";
}

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

Output:
ravi


with let:
Every variable declared with let is block scoped that is an if statement is also a block and a let variable inside if is only accessible inside of that if statement!

In the same way, if we declare a variable inside a function. then that function is the block scope and the variable is accessible inside that function!

Thread Thread
 
harshvdev profile image
Harsh

I understand it much more clearly now. Using let (instead of var) inside functions not only helps avoid bugs due to scope leakage but also makes the code more secure and predictable. Thanks for the explanation!

Collapse
 
dotallio profile image
Dotallio

I remember my first time switching from Python to JavaScript, those little differences really catch you off guard! Anything surprise you most about JS so far?

Collapse
 
harshvdev profile image
Harsh

Yeah, the function names are too long 🥲
Like ".tooUpperCase" instead of ".upper()" like in Python.