Start Javascript : learn about variables

Variables are the absolute base of programming. We wouldn't be able to do much without variables. We can find it in all the advanced concept of programming. It would be useless to program without it, dare I say.


This is a companion discussion topic for the original entry at https://blog.nathanaelcherrier.com/en/learn-javascript-variables/

New discussion on dev.to by Curtis Fenner:

I’m going to be nitpicky.

Variables in JavaScript do not have types. They have values, and those values have types. This is important to understand JavaScript, as it is to understand other dynamically typed languages; there is no restriction on which types of values any given variable can take on.

The JavaScript engine is capable of guessing (or “infer”) the type of a variable based on its value

JavaScript does not do any inference, as it has no static type system. This is called reflection , and it is not a guess – the language is mandated to keep the bookkeeping records which make it possible to determine, dynamically , what the type of any value is (again, not variable, but value).

Source: https://dev.to/curtisfenner/comment/f1e3

1 Like

New discussion on dev.to by Jon Randy:

const defines a constant. Constants are not variables. The clue is in the names:

  • constant’ - a place to store a value that once set, remains CONSTANT
  • variable’ - a place to store a value that remains VARIABLE, i.e. can later be used to store another value

Source: https://dev.to/jonrandy/comment/f1ha

New discussion on dev.to by Mike Ross:

Here’s something fun to show people. Watch how long the JSON string becomes between an array and an object in these two scenarios:

var a = [];
a[1111] = 1234;
a[2222] = 1234;
console.log(JSON.stringify(a));

as opposed to:

var a = {};
a[1111] = 1234;
a[2222] = 1234;
console.log(JSON.stringify(a));

Key point – you’ll often want to use objects instead of arrays.

Source: https://dev.to/volomike/comment/f1f8

1 Like