Javascript

MDIA 2294


CREATED BY :

David Lagou

A01057936

View Linkedin

3 Important Javascript Concepts

What is Javascript ?

Javascript, developed in 1995 was built in order to provide an accessible and complementary approach to java. Nowadays, javascript is used as a scripting language that allows users to implement complex features on web pages. This allows us to have dynamically updated content on web pages.


Variables are used in coding to retain data values within your code. When creating a variable, the "var" keyword must be placed in front of the name. The assignment operator "=" is used to assign a value to the variable. A variable can be a :

  • Numerical Value
  • A string
  • A collection of liked items (Array)
  • Function

1.1 Variable Declaration

You can declare a variable like this

You can't do this



1.2 Variable Scope

In JavaScript, a variables scope tells us where this variable can be accessed. There are three main types of variables :

  • Global - declared in the script tag but is outside of a function. A global variable can be used anywhere within the code.
  • Local - declared within the function. A local variable can only be used within the { } block
  • Block - declared within a "block" using let keyword. A block variable is only available

Global Variables example

As you can see "var a" was declared outside of the function scope but it is still accessible.


Local Variables example

In this example "var a" has been declared locally inside the " function foo". Using "var a " in "function bar" will result in an error because "var a " is bound to the scope of function.

It is important to remember to know the scopes of your variables

Block Variables example

As in the example, "let= i" only exists within the {} . This is denoted by the "let" variable type


1.3 Variable types

JavaScript has 6 different primitive variable types. JavaScript has dynamic types. This means that the same variable can be used to hold different data types.

Type Description
Null An abstract type. Null is the representation of no value.
Undefined An abstract type. This data type has no assigned value
Boolean A logical value that represents true or false
Numbers Real Numbers
Symbols Any set of character values ex: "John Doe"