Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
18 views

Unit-1 Javascripts

Uploaded by

Ayush Shrestha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
18 views

Unit-1 Javascripts

Uploaded by

Ayush Shrestha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 80
CACS. 205: Script Language PREPARED BY KRISHNA PD. ACHARYA (MECHI MULTIPLE CAMPUS) Java Script > JavaScript is used to create client-side dynamic:web pages. > JavaScript is an object-based scripting language which is lightweight and cross-platform. > JavaScript is not a compiled language, but it is a translated language. The JavaScript Translator (embedded in the browser) is responsible for translating the JavaScript code for the web browser. > JavaScript is a compact, object-based scripting language for developing client Internet applications > JavaScript was designed to add interactivity to HTML pages > A JavaScript is lines of executable computer code. > A JavaScript is usually embedded directly in HTML pages > JavaScript is an interpreted language (means that scripts execute without preliminary compilation). > Everyone can use JavaScript without purchasing a license. > All major browsers, like Netscape and Intemet Explorer, support JavaScript. > JavaScript was developed by Netscape as Live Script - changed to JavaScript when endorsed by Sun micro system 1993, version 1.0 released with Netseape 2.0 > JavaScript is a powerful scripting language that is also capable of performing extensive form data > JavaScript / ECMAScript > JavaScript was developed for Netscape: Netscape 2 was the first browser to run JavaScript. ¥ After Netscape the Mozilla foundation continued to develop JavaScript for the Firefox browser. » The latest JavaScript version was 1.8.5. (Identical to ECMAScript 5), > ECMAScript was developed by ECMA International after the organization adopted JavaScript » The first edition of ECMAScript was released in 1997. > JavaScript was invented by Brendan Eich in 1995, and became an ECMA standard in 1997. > ECMAScript is the official name of the language. > From 2015 ECMAScript is named by year (ECMAScript 2015). > ECMAScript is often abbreviated to ES. > ECMAScript 3 is fully supported in all browsers. > ECMAScript 5 is fully supported in all modern browsers Advantages of Java Script > Cross Browser supporting: This means that the JavaScript codes,are supported by various browsers like Internet Explorer, Netscape Navigator, Mozilla etc. > Platform Independent: JavaScript codes can be executed in any:platform like Linux, Microsoft Windows and many other operating systems. > Lightweight for fast downloading: The JavaScript codes runs directly in the client machine. The code should be downloaded all the way from server to the client and this time duration is very minimum and the executing the codes of JavaScript is also very fast. > Validating Data: The data can be validated in the two different way: Validating in server side or in server machine. Validating in client side or in client machine. In this two different types of validation of data the second one is much more faster, and is is done through JavaScript. Advantages of Java Script > Sophisticated User Interfaces: By using JavaScript you can create a'user interactive interfaces that can communicate with the user and the Browser. > In-Built software: To you dont need any extra:tools to write JavaScript, any plain text or HTML editor will do, so there's no expensive development software to buy. > Easy to Learn: The JavaScript programmer should know the minimal syntax of JavaScript since it supports many syntax and data types as C and C++. It's also an easy language to learn, and there's a thriving and supportive online community of JavaScript developers and information resources. > Designed for programming User-Events: JavaScript supports Object/Event based programming. So the code written in JavaScript can easily be break down into sub-modules. Disadvantages of Java Script > Launching an application on the client computer. JavaScript is not used to create stand-alone applications it is\only used to add some functionality in any web page. > Reading or writing files: JavaScript cannot read and write files into the élient mbachines. It can only be used as a utility language to develop any web site. > Retrieving the text contents of HTME pages or files‘from the server. > Reading and Writing files to the server JavaScript can read and write to any file in the server as well > Sending secret e-mails frem Web site visitors to you > JavaScript cannot be used to send email to the visitors ot user of the web site. This can be done only with the server side scripting. Cannot create Database Application: By using JavaScript you cannot connect the web site to the database. For this you need to use server-side scripting. > Browser Compatibility Issues: Not all browsers support the JavaScript codes. The browser may support JavaScript as a whole, but may not support the codes or lines of codes written in JavaScript and may interpret differently. > JavaScript does not implement multiprocessing or multithreading. > Use printers or other devices on the user’s system or the client-side LAN. JavaScript has limitations of writing in a client machine. It can only write the cockie in client machine that is also of ize ie. 4K. Application of Java Script JavaScript is used to create interactive websites, It is mainly used for: > Client-side validation, > Dynamic drop-down menus, > Displaying date and time, > Displaying pop-up windows and dialog boxes (like an alert dialog box, confirm dialog box and prompt dialog box), > Displaying clocks etc. > Provide event of based on user action to design CSS and HTML. > JavaScript can update and change both HTML and CSS > JavaScript can calculate, manipulate and validate data What it does? > JavaScript Can Change HTML Content > JavaScript Can Change HTML Attribute Values > JavaScript Can Change HTML Styles CSS) » JavaScript Can Hide HTML Elements Comparision java and Java Script Javascript [ova JavaScriptis a small lightweight programming language. | Javaisa full-blown powerful, sophisticated programminglanguage. Developed by Netscape communications: Developed by Sun Microsystems. Scriptinglonguage interpretedat runtime. True programming complied to byte-code. Object-based, has limitednumberof built-in objects. Object-oriented, can create their own classes. Not fully extensible. Variables type must not be declared. Javascriptsource code can be viewed by everybody using “view source command” Code integrated with, and embedded in HTML. Fully extensible | Applies cistinct from HTML [accessed from HTML pages). Variables type must be deciared Your Java source is hidden because If'sonly the | compiled byte-code, which the browser uses, but this isnot a guarantee of security. Coding Conventions Coding conventions are style guidelines for programming. Coding conventions can be documented rules for teams to follow, ‘or just be your individual coding practice. They typically include: > "Naming and declaration ules fer variables aac > Rules for the use of white space, indentation, and comments. » Programming practices and principles » Coding conventions secure quality: which may include improves code readability and make code maintenance easier. Xaming Conventions > Alyse the seme naming. vent orale code. For exazpe: > Nuiable aul function sage tg camelCase * Global variables written in UPPERCASE (We don't, but it's quite common) » Constants (like PI) written in UPPERCASE » Should you use hyp-hens, camelCase, or under scores in variable names. Hyphens in HTML and CSS: > TEIMLS atubutes can tart wit dta-(ata-quany attics) CSS uses hyphens in propert es (font-size), Hyplen are at allowed in JaveSont mans Underscores: > Many programmers prefer to use underscores (date_of birth), especially in SQL databases. : Coding Conventions > HTML files should have a-html extension (not htm). > CSS files should havea .css extension. > JavaScript files should have a js extension: Use Lower Case File Names ‘Most web servers (Apache, Unix) are ease sensitive about file names: Jondon jpg cannot be accessed as London. jpg. Other web servers (Microsoft 11S) arenot case Sensitive Jondon,jpg can be accessed #s Loudon jpz or london jpe Ifyou use a mix of upper and lower case, you have to be extremely consistent, Ifyou move fiom a case insensitive, to a case sensitive server, even small exrors can break your web site. To avoid these problems, always use lower case file names (if possible). Performance > Coding conventions are not used by computers. Most rules have little impact on the execution of programs. > Indentation and extra spaces are not significant in small scripts For code in development, readability should be preferred. Larger production scripts should be minified. Coding Conventions Avoid global variables, avoid new, avoid ==, avoid eval() Avoid Global Variables Minimize the use of global variables. This includes all data types, objects, and functions: Global variables and functions can be overvmitten by other scripts. Always Declare Local Variables All variables used in a function should be declared as logal variables Local variables must be declared with the var Keyword or the let keyword, otherwise they will become global variables. Striet mode does not allow undeclared variables. Declarationson Top This a good coding practice to put all declarations at the top of each script or function. This will: Give cleaner code Provide a single place to look for local variables ‘Make it easier to avoid unwanted (implied) global variables Reduce the possibility of unwanted re-declarations. By default, JavaScript moves all declarations to the top. Initialize Variables This a good coding practice to initialize variables when you declare them. This will: Give cleaner code de a single place to initialize variables JavaScript Comments > JavaScript comments can he used to explain JavaScript code, and to make it more readable, > JavaScript comments can also be used to prevent execution, when testing altemative code. Single Line Comments ® Single line comments start with //. > Any text between // and the end of the line will/be ignored by JavaScript (will not be executed), /) Change heading: ‘Mheadking hl has the id=t1 document. getElementByld(“t1").innecHTML ="My First Page" /-tine Comments ine comments start with /* and énd with * > Any text between /* and */.will beignored by IavaScript. p The code below will change the heading with id ="myH" and the paragraph with id= "myP" in my web page: " document getElement Byld("t1").imeHTML ="My First Page” pt> tag in java Scrip 1e tag defines an altemate content for users that have disabled scripts in their browser or have a browser that doesnt support script. The