JavaScript – Basics

JavaScript, initially called LiveScript is a robust client-side scripting language, used mainly for make your webpage more interactive. This also helps in communicate data between the server and the browser.

JavaScript is also used in game development and mobile application development. It Also help in reduce the traffic of server side.

JavaScript was developed by Brendan Eich in 1995, which appeared in Netscape, a popular browser of that time.

Please note that JavaScript and Java are very much unrelated. Java is a very complex programming language whereas JavaScript is only a scripting language.

 

Limitation of JavaScript

  1. JavaScript doesn’t support any network related programming.
  2. JavaScript doesn’t support multithreading

 

JavaScript Output

JavaScript can display data in following ways:

 

Dialog boxes() – Display output using alert, prompt and confirm dialog boxes

document.write() – Used to insert text onto your web page (this text can actually be HTML elements).

innerHTML – Used to display output in a specific place or in a division

console.log() – Used to display output on the console of a browser.

 

JavaScript – Variables

A variable is basically an identifier for a value or simply the Variables are used to store values or expressions

The way to use variables is by using the var keyword followed by the variable name.

Example:

var empName;

In this line of code, I declared a variable called empName. Right now, It doesn’t contain any value. So initialization is required here –

Example:

var empName = “Hernan”;

Naming Variables

Following things should be follow when naming them:

– Your variable name should be meaningful or be a noun.

– Your variables can start with a letter, underscore, or the $, they can’t start with a number.

– Spaces are not allowed.

– Variable name should be unique and should not be a keyword.

 

Function in JavaScript

A function is nothing more than a wrapper for some code. A function is a block of code which will be executed only if it is called.

So A Function is a:

– Groups statements together

– Makes your code reusable

Syntax

function functionname()

{

//Set of statements here

}

 

 

Example:

function test()

{

alert(“hello.. Lets learn functions in JS”);

}

The last thing to look at is the function call:

test();

 

Leave a Reply

Your email address will not be published.

Enjoy the tutorial? Please spread the word :)

Follow by Email
Facebook
Facebook
Google+2k
Google+
http://hirdeshbhardwaj.com/2017/01/25/javascript-basics
YouTube39
YouTube