Title: Introduction to JS Bellal University of Bisha
1Introduction to JavaScriptCode IS 435
- Prepared by
- A.K.M Bellal Hossain
- UB- Al Namas
2JS and History
JavaScript is everywhere, and for the seventh
year in a row, it has been ranked the most
commonly used programming language, with 67.8 of
developers employing it in 2019. Its ascent to
the worlds most popular programming language is
synonymous with the rise of the internet
itself. Created out of necessity, it is used to
build 95.2 (1.52 billion) of websites today,
including some of the worlds largest, like
Facebook and YouTube. Without it, we would not
have popular and useful web apps such as Google
Maps and eBay.
In September 1995, a Netscape programmer named
Brandan Eich , developed a new scripting language
in just 10 days. It was originally named Mocha,
but quickly became known as LiveScript and,
later, JavaScript
3About JavaScript
- Joint venture Sun Netscape
- Netscape Communications
- LiveScript
- Sun Microsystems
- Simplify its Java language
- Open language anyone can use
- Embedded in the HTML document
4JavaScript vs. Java
- Java is full-fledged, object-oriented language
- Can be used to create applets
- Applets small programs designed to execute within
another application - Must use some type compiler, such as Suns JDK
5JavaScript
- Statements/variables are case sensitive
- Interpreted language code runs only on a
JSinterpreter built into browser - Version of JS depends on browser version
- IE supports additional features Microsoft
callsits version Jscript - Older browsers may not handle newer JS codes
6JavaScript and HTML Tags
- HTML (hypertext markup language)
- Microsoft FrontPage
- Macromedia Dreamweaver
- Microsoft Word
- Netscape Composer
- Text editor, such as Notepad
- Tag instruction surrounded by lt (lt) and gt (gt)
symbols - The instructions are call attributes and have
values assigned to them
7SCRIPT Tags
- Four attributes
- LANGUAGE identifies version of JavaScript
- SRC text string for URL/filename of JS source
file - TYPE specify the scripting language
- DEFER beyond the scope
- TagAttributeslt ltSCRIPT LANGUAGE JavaScriptgtgt
lt! Hide from old browsers Place your JS code in
this area //--gt lt/SCRIPTgt
8Comments
- HTML Comments
- Embedded JS code needs to be hidden from
incompatible browsers - lt!-- beginning comment block
- --gt ending comment block
- JavaScript Comments
- Line Comments
- // This is a line comment Block Comments
- / Beginning line
- Still a comment
- Ending line /
-
9Cookies and Benefits of JS
- JavaScript Benefits
- Web Standard
- Alternative Microsoft VBScript
- Follows Visual Basic syntax
- VBScript not supported in Netscape Navigator
- Provide instant feedback without CGI (Common
Gateway Interface) scripts - JavaScript Cookies
- Cookies data sent and stored in files on users
computer - Navigator cookies.txt
- IE Cookies folder
- Track users preferences
- JavaScript code limits access to users hard drive
browser controls cookie location
10Java Script Basics
- Common types of variables
- Numeric - numbers
- Strings - letters
- Boolean true/false or yes/no
- Variables Naming Conventions
- Name must begin with letter or underscore
- Rest of name letters, numbers, or underscores
- Avoid reserved words (appendix A)
- No spaces or punctuation
- Variables are case sensitive
- Defined by keyword var
11Object, Properties and Methods
- Object real-world entity (book, car)
- JS is object oriented (OO)
- Object-Oriented Programming (OOP)
- Object is described by its properties
- Properties are attributes that help
differentiateone object from another - Separate object and property with a period
- Ex. car.color red
- Method function or action you want the object to
perform (behavior) - Ex. car.drive()
- Some methods require an argument
- Argument is a value passed to the method
- JS uses many objects, but not a complete OOP
language - JS provides many built-in objects
- Ex. Date, Arrays, windows, and forms
- JS allows you to define and create your own