Showing posts with label arithmetic operators. Show all posts
Showing posts with label arithmetic operators. Show all posts

Monday, 22 February 2016

Javascript - Programs Basic

Javascript Programs
In a programming language, computer program instructions are called statements.
JavaScript is a programming language and JavaScript statements are separated by semicolons.

Example:
var a = 1;
var b = 2;
var c = a + b;

And next is the javascript statements, and it includes 

  • values
  • operators
  • expressions
  • keywords and 
  • comments

JS Values:
JS values are two types, literals (fixed values) and variables

Numbers - 10.50,100
String - with single or double quote"name"

Variables:
Variables are used to store data values. JS uses var keyword to assign variables.
Eg: 
var x;
x=10;

Operators:
JS uses an assignment operator ( = ) to assign values to variables: 
var a=90;
JS uses arithmetic operators ( + - *  / ) to compute values: 
a * 10 (expressions)
also in string level
 "Mark" + " " + "Layer", evaluates to "Mark Layer":

Comments:
Code after double slashes // or between /* and */ is treated as a comment.Comments are ignored, and will not be executed:

Eg:
var a = 50;   // I will be executed

// var a = 50;   I will NOT be executed

JS Statements:
JS statement tells the browser to write "I am in." inside an HTML element with id="example":
Example:
document.getElementById("example").innerHTML = "I am in.";

One program example:

var a = 5;
var b = 6;
var c = a + b;
document.getElementById("example").innerHTML = c;