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
, andvar
. - Used
alert()
andconsole.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)
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)!
I just checked. It's complicated... Doesn't seem as easy as Python.
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!
Output:
ravi
with
let
:Every variable declared with
let
is block scoped that is anif
statement is also a block and alet
variable insideif
is only accessible inside of thatif
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!
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!
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?
Yeah, the function names are too long 🥲
Like ".tooUpperCase" instead of ".upper()" like in Python.