DEV Community

Wadi zaatour
Wadi zaatour

Posted on • Updated on

Javascript and Variables

Javascript is an object-oriented scripting language to ensure webpages interactivity.

It contains a standard library of objects likeArray, Date, Mathas well as a core set of language elements such as operators, control structures and statements.

Who owns the Javascript?

JavaScript is not owned by a single individual, it is an open standard maintained by the Ecma International organization

Let's dive into more technical side

Javascript can be extended to variety of purposes:

Client-side JavaScript enhances the core language by providing objects to manipulate a browser and its Document Object Model (DOM), allowing applications to dynamically modify HTML forms, respond to user events like clicks and input, and navigate pages.

Server-side JavaScript extends the core language by supplying objects tailored for server environments, enabling tasks such as database communication, persistent data storage across application invocations, and server-side file manipulations, enhancing the functionality and scalability of web applications.

It consists of three kinds of Variable declarations:

  • var declares a variable, optionally initializing it to a value.
  • let declares a block-scoped, local variable, optionally initializing it to a value.
  • const declares a block-scoped, read-only named constant.

There is 3 types of Variable scope

Let's explain them better:

  • Global scope: The default scope for all code running in script mode.
  • Module scope: The scope for code running in module mode.
  • Function scope: The scope created with a function.

In addition, variables declared with letor constcan belong to an additional scope:

Block scope: The scope created with a pair of curly braces (a block).

One more thing about Variable hoisting:

In JavaScript, variable hoisting moves variable declarations to the top of their scope during compilation, allowing access before their actual position in the code.

  • var is hoisted means statements in a function should be placed as near to the top of the function as possible.

  • let and const are hoisted is a matter of definition debate. Referencing the variable in the block before the variable declaration always results in a ReferenceError

Top comments (0)