Vous êtes sur la page 1sur 4

JAVASCRIPT

1. A JavaScript program consists of statements and expressions formed from


tokens of various categories, including keywords, literals, separators,
operators, and identifiers placed together in an order that is meaningful to a
JavaScript interpreter, which is contained in most web
browsers.JavaScript syntax is the set of rules, how JavaScript programs are
constructed.A computer program is a list of "instructions" to be "executed" by the
computer.In a programming language, these program instructions are
called statements.JavaScript is a programming language. JavaScript statements
are separated by semicolons.

Javascript has String, Number, Boolean, null, undefined, Object datatypes.


String : var name = Tariq Taeem;
Number: var id = 94;
Boolean: var x = True;
Object : var z = [banana, apple, Litchi];
Null: var money = null;
Undefined: var person;
Ps- array, null and objects are considered as Object.
2. Reserved Keywords
Javascript has some reserved keywords which cant be used for any other
perpose like variable names, function name etc.
JavaScript Reserved Words
break

export

return

case

for

switch

comment

function

this

continue

if

typeof

default

import

var

delete

in

void

do

label

while

else

new

with

3.document object
document.write object is used to print something in webpage, its same like
printf in C programming.
if we write document.write(Hello! How Are You?);
it will print
Hello! How Are You?
4.Local Variables and Global Variables
Local variable : Local variable is which we can use only for certain program
and it cant be used for any other program lets see a example to clarify this.
Like we have a function which has two variable x and y
inside it so if we want to run it it will run undoubtlly, but if we want to use
them anywhere else it will not response or run and these are called local
variables.
but if we had taken the
function add(){
x = 5;
y = 3;
sum = x + y;
return sum
}
document.write(add());
But if we had taken those two variables outside the function, those variable
would had been working for that function and even if we wanted to call those
variables for other tasks to perform they would do that,so as they are doing
everyones tasks they are called global variables .
Var x = 96;

Var y = 54;
function add(){
sum = x + y;

return sum
}
document.write(add());
5. Conditions of Variables
The general rules for constructing names for variables (unique identifiers)
are:

Names can contain letters, digits, underscores, and dollar signs.

Names must begin with a letter.

Names can also begin with $ and _ .

Names are case sensitive (y and Y are different variables).

Reserved words (like JavaScript keywords) cannot be used as names.

6.Object
Objects are variables too. But objects can contain many values.
We use object JS like this
var car = {type:"Fiat", model:500, color:"white"};
7. Concatenation
Concatenation is a way to add strings, numbers, arrays etc in one statement easily
in JS.
A simple example:

firstName = "Rifat";
age = 27;

country = "Dhaka";
brother = "Rahat";
designation = "Mentor";
company = "Coderstrust";
classStart = 3;
year = 2015;
space = "";

document.write("Hello! My name is " + firstName + " My age is " + age +


". I live in " + country + ". <br> I have a brother his name is " + brother
+ ". I work at <br> " + company + ", i am one of the lead " + designation +
" here."
+ " my class starts at " + classStart + " pm. <br> I have joined here in " +
year +"."
);
It will Print
Hello! My name is Rifat My age is 27. I live in Dhaka.

I have a brother his name is Rahat. I work at


Coderstrust, i am one of the lead Mentor here. my class starts at 3
pm.
I have joined here in 2015.