+ All Categories
Home > Education > Java script basic

Java script basic

Date post: 12-Apr-2017
Category:
Upload: admec-multimedia-institute
View: 1,016 times
Download: 0 times
Share this document with a friend
21
JavaScript Basics ADMEC MULTIMEDIA Leader in Animation & Digital Media Education ISO 9001:2008 CERTIFIED | ADOBE Testing Center www.admecindia.co.in
Transcript
Page 1: Java script basic

JavaScript Basics

ADMEC MULTIMEDIA

Leader in Animation & Digital Media Education

ISO 9001:2008 CERTIFIED | ADOBE Testing Centerwww.admecindia.co.in

Page 2: Java script basic

Contenti. What is JavaScript?ii. Use of JavaScript?iii. Features of JavaScript Popups Variable Scopes Functioniv. DATATYPE in JavaScript Number String Undefined Boolean Nullv. Operators in JavaScript Assignment Operator Equality Operator Strict Equality Operators

Page 3: Java script basic

What is JavaScript?

JavaScript is scripting/programming language. File Extension of JavaScript is ".js”. This extension can be catched by a number of applications including Windows Script Host, Dreamweaver MX, Notepad, Netscape Navigator, PavScrip, UltraEdit.

JavaScript is also considered as "assembly language of the web". JavaScript is totally user based. It is does not store any in-built data or function.JavaScript is object oriented. We can also create small objects with help of basic JavaScript.

Page 4: Java script basic

Use of JavaScript?

JavaScript is also used to make websites rich and dynamic. Almost every website have JavaScript used in it. It tells how JavaScript important for us.

There are plenty of websites and applications which are using JavaScript such as: Gmail, Google, YouTube, Yahoo, LinkedIn, Twitter, Facebook etc...

Page 5: Java script basic

Features of JavaScriptPOPUPSPopup is additional display box/window surprisingly comes over web browser with information & notice.• Alert: Is any notice to the viewer & provide

only option to "OK" after reading.Example: alert('welcome to js');

 • Confirm: It is useful to display any of

information/ message to viewer which let them decide for accepting & rejecting information with option of "OK" & "CANCEL“

Example: confirm('Are u sure to visit this page?');

 

Page 6: Java script basic

• Prompt: Take input (info/text/massage/name-- alphabetic value) from Viewers.

 Example: prompt('Enter ur name plz');

Page 7: Java script basic

VARIABLE:

Variable is a kind of container with limited space where we can put value (Numeric, String, Boolean [true/false], objects etc) just for one time if we try to put 2nd value 1st will automatically eliminate. Variable can be identified with unique names.

Variable are restricted with some special characters (symbols) like we can only use underscore (_), dollar ($) and Alpha Numeric character. The right way to write variables

var myNum = 45;var my_num = 55;var num1 = 11;var num = 78  

 

Page 8: Java script basic

SCOPES:

Scope is set of Variable, objects and Function you can use. (Local & Global)

Maintain accessibility through variable & function.

There are 2 Variable used: Local Variable & Global Variable

In Local Scope, Variable is declared within the Function whereas Global Scope, Variable is Declared Outside the function.Data remain secure if we used local Variable.

Page 9: Java script basic

FUNCTION:

A function is a group of reusable code which enables a programmer to create a code that is in better organization and execution and which can be called anywhere in your program. In short function eliminates the repetitive writing of same codes.

Function helps a programmer to divide a big program into a number of small chunks of program and also helps in managing functions easily & effectively. The most common way to define a function in JavaScript is by using the keyword “function”.  

 

Page 10: Java script basic

Syntax of function:

function main() //head of the function, these brackets () are called parenthesis{

//body of the function} Types of function: Named Function & Anonymous Function Examples:

Named function:function main(){}Note: declared a 'main' function. The name of the function is 'main'.   

 

Page 11: Java script basic

Unnamed function:

var main = function (){} Note: Declared an unnamed function and at the same time assigned to a variable 'main'. You can't declare a function without the name so you need to store that in a variable. This type of declaring method of function known as 'closure' in JavaScript. 

 

Page 12: Java script basic

DATATYPE in JavaScriptThere 5 Primitive Datatypes given below:

Number: A JavaScript programmer all the time have to

deal with numbers. It is a value and we use it in various operations in the application or website. Some times you can't get the expected result and either your program gets broken or filled with errors because of non-numeric types of values.

JavaScript offers main 3 functions to convert any of the value to number.

Numbers can be written with or without decimals.

Page 13: Java script basic

Example:

var num = 10.25;1. alert(Number(num)); //10.252. alert(parseInt(num)); //103. alert(parseFloat(num)); //10.25

String: String (value) is used to represent text related

data. String is also a set of “element” of 16-bit unsigned integer value which start from the first element is ZERO and the next is ONE and so on at index.

We can use string literals in scripts by enclosing them in single or double quotation marks e.g. (‘ ’, “ ”).

Page 14: Java script basic

Example:

Single Quotation Markalert('you clicked on CANCEL'); Double Quotation Markalert("you clicked on \"OK\"");

Note: In JavaScript, does not have a type to represent a single character. To represent a single character in JavaScript, we have to create a string that contain only single character. A string that contains empty string or zero characters ("") is an empty or string with zero-length.String(value) function can be used to convert any value to string datatype.  

Page 15: Java script basic

Undefined:

Undefined is a variable which doesn’t have any defined value. Example:

var num; // contains no value alert(num);// will get undefined

Page 16: Java script basic

Boolean: Boolean have two values i.e. “true or false” or 1 or 0 and are logical representative.Example:if(confirm('Are you sure to leave this page')){

//you will be redirected to the following URL if above condition is true means if someone clicks on the OK button

window.location.href = 'http://www.admecindia.co.in';}else{

//nothing will happen if someone clicks on CANCEL button as you will receive false as the result

return false;}Note: In above example you either get True or False depends on the button you clicked means you are getting a Boolean value.

Page 17: Java script basic

Null: Null is exactly having single value when Null is defined or nothing. Null is considered as an object in JavaScript.

var my_value = null;alert(my_value * 20); //0

Note:1. null gets converted to the false boolean value and i.e. 0 too2. null and 'null' both are different terms completely3. null can be used when you want to reset a variable or want to store nothing 

Page 18: Java script basic

NOTE

There are 2 other datatypes considered according to ECMAScript standard.

Symbol: symbol as in primitive datatype which are unique and unchangeable. In some programming language they are also called “atoms”.

Object: object data type refers to the structure consist of data & information for working with the data.

Page 19: Java script basic

Operators in JavaScript

Types of Operators: Assignment Operator: The equal sign (=) is

called “Assignment” Operators.

Equality Operator: when double the equal sign (==) is called “Equality” Operator. Is also called comparison Operator.

Strict Equality Operators: when Triple the equal sign (===) is called “Strict Equality” Operator. Is also called comparison Operator.

  

Page 20: Java script basic

Remark

These are just the basics of JavaScript and all these topics play a vital role when you create something using JavaScript.

As much you are familiar with these basics more you would be strong in JavaScript.

Page 21: Java script basic

Contact Us:ADMEC MULTIMEDIA INSTITUTEC-7/114, IInd Floor, Sector- 7, Rohini, Delhi- 85Landmark: Near Rohini East Metro StationHelpline 1: +91 9811 818 122Helpline 2: +91 9911 782 350

ADMEC MULTIMEDIA Leader in Animation & Digital Media Education ISO 9001:2008 CERTIFIED | ADOBE Testing Center

ADMEC MULTIMEDIA INSTITUTE For More information you can visit :

http://www.admecindia.co.in


Recommended