JavaScript { Part 3 : Basics }

Photo by Joe Shillington on Unsplash

Ok guys, honestly I would like to begin to say that in my years in programming, a lot of guys are not in the knowledge or complete understanding of the subjects that I’m presenting today …

Primitives data types

  • String
  • Number
  • Boolean
  • Null
  • Undefined
  • Symbol ( new in es6 )

== VS ===

In JavaScript are two types of equality operators, each one has a purpose and each one has an inequality, the strict equality, and normal equality.

Strict : ( === )

This type consider only values that have the same type to be equal

  • undefined === undefined
  • null === null
  • boolean === boolean
  • string === string
  • everything else : not strictly equal
  • objects … let’s say that in this case, you need to use your own comparison algorithm because if you compare two objects it would be false
var first_object = {}, second_object = {};
first_object === second_object
=> false
first_object === first_object
=> true
second_object === second_object
=> true

Normal : ( == )

This type tries to convert values of different types before comparing them as with strict equality.

For me, this way is a little messy because is confusing the way convert the values

  • For example, the null and undefined are considered equal
null == undefined
=> true
  • A string and a number, the string its convert to a number
‘5355’ == 5355
=> true


Always try to use strict equality and please as much as you like to use normal equality try to avoided


For the purpose of writing good code, you need to understand that scope is the current context of the code.

The scope refers to the accessibility of functions and variables. There exist a global and local scope.

function bla () {
var my_variable;

Here, the direct scope of my_variable is the function bla().

Shadowing : if a scope declares a variable that has the same name as one of his surrounding scopes, changes to the inner variable do not affect the outer variable, which is accessible again after the inner scope is left :

var my_variable= ‘global’;
function bla() {
var my_variable = ‘local’;
console.log(my_variable); // => local
console.log(global_variable); // => global
// => local
console.log(global_variable); // => global

inside the function bla(), the global my_variable is shadowed by a local my_variable.


Make it simple, var, let, and const, are just the way you could be assigned a variable but…

Const : Means that the value can’t be reassigned ( i like it because maintain my code clean).

Let : The value of the variable may be reassigned, this kind is only available on the block it’s defined in.

Var : Its the old school way to declare a regular global and local variable but are some identifiers which are reserved words, the next ones can’t be used for a variable name…

// => Do not use it as a variable name
arguments, break, case, catch, class, const, continue, debugger, default, delete, do, else, enum, export, extend, false, finally, for, function, if, implements, import, in, instanceof, interface, let, new, null, package, private, protected, public, return, static, super, switch, this, throw, true, try, typeof, var, void, while

Thank you very much for your time. And, until next time, have a great day!

Did you enjoy this? Give it a clap on the left so others can discover it as well or follow me if you are interested in more chapter like this.