Home

Javascript is a programming language of the web. It was invented by Brendan Eich in 1995.

Why learn Javascript

  1. It's the most popular programming language.Javascript helps you develop great front-end as well as back-end softwares using different Javascript based frameworks like jQuery, Node.JS etc.
  2. JavaScript is everywhere.It comes installed on every modern web browser and so to learn Javascript you really do not need any special environment setup.
  3. It's a valuable tool for game designers. Games are a big business today, and developers who know JavaScript have that extra advantage. The language's versatility, power, and ability to easily create visual effects make it a perfect fit for game developers.
  4. Javascript helps you create really beautiful and crazy fast websites. You can develop your website with a console like look and feel and give your users the best Graphical User Experience
  5. JavaScript is easy to learn

Javascript Frameworks

Thera are many javascript frameworks and libraries. They include:

  1. Angular
  2. React
  3. JQuery
  4. Vue.js
  5. Meteor
  6. Node.js
  7. Ember.js

Introduction
Javascript is a tranlated language. JavaScript is an object-based scripting language which is lightweight and cross-platform.

JavaScript History

In 1993, Mosaic, the first popular web browser, came into existence. In the year 1994, Netscape was founded by Marc Andreessen. He realized that the web needed to become more dynamic. Thus, a 'glue language' was believed to be provided to HTML to make web designing easy for designers and part-time programmers. Consequently, in 1995, the company recruited Brendan Eich intending to implement and embed Scheme programming language to the browser. But, before Brendan could start, the company merged with Sun Microsystems for adding Java into its Navigator so that it could compete with Microsoft over the web technologies and platforms. Now, two languages were there: Java and the scripting language. Further, Netscape decided to give a similar name to the scripting language as Java's. It led to 'Javascript'. Finally, in May 1995, Marc Andreessen coined the first code of Javascript named 'Mocha'. Later, the marketing team replaced the name with 'LiveScript'. But, due to trademark reasons and certain other reasons, in December 1995, the language was finally renamed to 'JavaScript'. From then, JavaScript came into existence.

Application of Javascript

  1. Web application
  2. Web Development
  3. Mobile Application
  4. Game Development
  5. Client-side Validation
  6. Server Applications
  7. Web Server
  8. Presentations and slideshows
  9. Dynamic drop-down menus
Syntax

JavaScript is implemented using JavaScript statements that are placed within script in HTML head.

Case Sensitivity

JavaScript is a case-sensitive language. This means that the language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters. City and city in JavaScript have two very different meanings.

Comments

JavaScript comments are meaningful way to explain complex code in simple plain English. Comments can also be used to add suggestions or put warnings in code. Any JavaScript comment is ignored by the web browser. There are two different ways to write comments in Javascript on a;

  1. Single line
  2. Multiple lines

Single line comments

Single line comments begin with two forward slashes (//).

//Declare variable X and give it a value of 10.
let X=10;
//Declares variable Y and adds 5 to the variable X
let Y=5+X

Multiline (Block) comments

Multi-line comments start with /* and end with */ . Any text between /* and */ will be ignored by JavaScript.
/*
This is a multiline comment 1
This is a multiline comment 2
This is a multiline comment 3
This is a multiline comment 4
This is a multiline comment 5
*/
Variables

A variable is a storage location. There are a set of rules one needs to observe when naming variables:

  1. Name must start with a letter (a to z or A to Z).underscore( _ ), or dollar( $ ) sign.
  2. Names can contain letters, digits, underscores, and dollar signs.
  3. Name must not be a reserved words.
  4. After first letter we can use digits (0 to 9), for example value1.
  5. JavaScript variables are case sensitive, for example x and X are different variables

Variable Syntax

When declaring a variable one must declare with either let or const. If you want a general rule: always declare variables with const. If you think the value of the variable can change, use let. For example:
const name; // declares a variable called name.
or
let Area; //declares a variable called area
In JavaScript creating a variable is called variable declaration. Storing a value in a variable is called variable initialization. An example is:
//initializes a variable called width to 5
let width=5;

Javascript Variable Scope

In javascript there are two types of variables:

  1. Local Variable - A local variable is declared inside a function. It can only be accessible in that function.
  2. Global Variable - A global variable has global scope which means it can be defined anywhere in your JavaScript code.

//local variables
function sum(){
let x = 10;
let y = 5;
let z = x + y;
} //global variable let greetings = Buenos días;
functionmorning(){
console.log(greetings);
}//the function above will output Buenos días
Operators
JavaScript operators are symbols that are used to perform operations on operands. For example;
var multiply = 10 * 20;
In the example above, 10 and 20 are the operands while = is the operator. Javascript has the following operators;
  1. Arithmetic operators
  2. Comparison Operators
  3. Bitwise operators
  4. Logical operators
  5. Assignment Operators
  6. Special Operators

Arithmetic Operators

Arithmetic operators perform arithmetic operation on operands. They include:

OperatorDescriptionExample
+Addition60+20 = 80
-Subtraction20-15 = 5
*Multiplication5*20 = 100
/Division 20/10 = 2
%Modulus (Remainder)20%10 = 0
++Incrementvar b=20; a++; Now b = 21
--Decrementvar b=20; a--; Now b = 19

Comparison Operators

Comparison operators compare values between two operands. They include:

OperatorDescriptionExample
==Is equal to10==20 = false
===Identical (equal and of same type)10==20 = false
!=Not equal to10!=20 = true
!==Not Identical 20!==20 = false
>Greater than20>10 = true
>=Greater than or equal to20>=10 = true
<Less than20<10 = false
<=Less than or equal to20<=10 = false

Bitwise Operators

Bitwise operators perform bitwise operations on operands. Bitwise operators include;

OperatorDescriptionExample
&Bitwise AND(10==20 & 20==33) = false
|Bitwise OR(10==20 | 20==33) = false
^Bitwise XOR(10==20 ^ 20==33) = false
~Bitwise NOT (~10) = -10
<<Bitwise Left Shift(10<<2) = 40
>>Bitwise Right Shift(10>>2) = 2
>>>Bitwise Right Shift with Zero(10>>>2) = 2

Logical Operators

The following operators are known as JavaScript logical operators

OperatorDescriptionExample
&&Logical AND(10==20 && 20==33) = false
||Logical OR(10==20 || 20==33) = false
!Logical Not!(10==20) = true

Assignment Operators

The following operators are known as JavaScript assignment operators

OperatorDescriptionExample
=Assign10+10 = 20
+=Add and assignvar a=10; a+=20; Now a = 30
-=Subtract and assignvar a=20; a-=10; Now a = 10
*=Multiply and assignvar a=10; a*=20; Now a = 200
/=Divide and assignvar a=10; a/=2; Now a = 5
%=Modulus and assignvar a=10; a%=2; Now a = 0

Special Operators

The following operators are known as JavaScript special operators

OperatorDescription
(?:)Conditional Operator returns value based on the condition. It is like if-else.
,Comma Operator allows multiple expressions to be evaluated as single statement.
deleteDelete Operator deletes a property from the object.
inIn Operator checks if object has the given property
instanceofchecks if the object is an instance of given type
newcreates an instance (object)
typeofchecks the type of object.
voidit discards the expression's return value.
yieldchecks what is returned in a generator by the generator's iterator.
Function

A function is a reusable block of code that performs a specific task.

Function Syntax

A JavaScript function is defined with the function keyword, followed by a function name, followed by parentheses ().

function functionname(){
//block of code
}

In the parentheses, parameters can be passed. The parameters are separated by a comma.
function identifier(parameter 1, parameter 2, parameter 3){
//block of code
}

Calling a function

To call a function, you type the function name followed by parentheses.

//create a function called animal
function animal(){
console.log("I love dogs");
}
//calls the function animal
animal();

Return statement

To pass information from a function, Javascript uses return statement. When JavaScript reaches a return statement, the function will stop executing.

function rectanglearea(){
let width=10;
let height=5;
let area=width*height;
return area;
}