Introduction to Javascript

Javascript is a scripting or dynamic computer programming language. It works asynchronously. Javascript can change an updated HTML and CSS. Nowadays javascript can be used client-side and server-side also.

Javascript Primitives Value: javascript has 7 primitive data types number, string, boolean, symbol, bigint, Undefined and Null. All primitives are constant, they cannot be altered.

OOP in Javascript: OPP stands by object-oriented programming. OOP is faster and easier to execute. It provides clean code.

What is ES6: In June 2015 javascript release the 6th edition ECMAScript 6 (or ES6) and later renamed ECMAScript2015. Javascript ES6 brings so many new features and syntax.

Block Bindings: In JavaScript, variable declare is an important factor. In a variable declaration, it depends on which methods you will declare a variable and where it will be. ES6 provides a new way to declare so that you can more easily control the scope of variables.

Block-Level Declarations: Block-level declarations mean the declared variable is not accessible outside the block scope Block scopes are created:

  1. Inside of a function
  2. Inside of a block (indicated by the { and } characters)

Var Declarations and Hoisting: Variable declarations using var are treated as if they are at the top of the function (or global scope, if declared outside of a function) regardless of where the actual declaration occurs; this is called hoisting. Example-

in the example, the variable is declared to the inside of the if condition. so that the name variable is not accessible on the else condition and outside of the condition.

The declaration of name variable is hoisted to the top. That means the variable name is accessible from the else condition. If accessed from there, the variable would just have a value of undefine because it hasn’t been initialized.

Let Declarations: The let and var declaration syntax is the same. You can use let in place of declaring var. And if you do this you have to remember that the scope of the variable will remain in the current block because var is hoisted on the top of the function but let is not hoisted.

Const Declarations: If we declared a variable with the const variable, we can’t change this value. The value is constant.

Block Binding in Loops: In JavaScript, most often case developers want block-level scoping of variables is within for loops. For for this we have to use let not var, cause var is being hoisted. Follow the two examples below:

Here, outside the loop, i is accessible because we use var

--

--

Front-end developer.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store