JavaScript Notes PDF
Document Details
Uploaded by InstructiveNephrite4861
Universiti Utara Malaysia
Tags
Related
Summary
These notes cover JavaScript, a client-side scripting language used for web development. They explain the basic concepts, syntax, and how to use it in projects.
Full Transcript
JS JAVASCRIPT Client Side Script Objectives Understand the concept of JS Knowing the syntax Use JS in project ...
JS JAVASCRIPT Client Side Script Objectives Understand the concept of JS Knowing the syntax Use JS in project Basics JavaScript How to JavaScript External Introducti JavaScript JavaScript Enable Popup JavaScript on Syntax and HTML JavaScript Boxes File JavaScript JavaScript JavaScript JavaScript JavaScript JavaScript If Switch Operators Variables Functions Events Statement Statement s JavaScript JavaScript JavaScript JavaScript JavaScript While Escape Void(0) For Loop Try Catch Loop Characters What is JavaScript? JavaScript is a programming language. JavaScript is Object Based Programming language NOT Object oriented. JavaScript and JAVA are not same. JavaScript is weakly typed, Client side Interpreted Language. Designed by Brendan Eich for Netscape. It was originally called Mocha, renamed to LiveScript, and then renamed to JavaScript. the official standard is just called ECMAScript. Features of JavaScript js JavaScript is a scripting language that enables web developers/designers to build more functional and interactive websites. Alert messages Popup windows Common uses of Dynamic dropdown JavaScript include: menus Form validation What is Displaying date/time JavaScript?(cont.) JavaScript usually runs on the client-side (the browser's side). Java and JavaScript are two different things What do I need to create JavaScript? You can create JavaScript using the same equipment you use when creating HTML. That is: Computer Text editor. For example, Notepad (for Windows), Pico (for Linux), or Simpletext (Mac). You could use a HTML editor if you like but it's not needed. Web Browser. For example, Google Chrome, Safari, MS EDGE or Firefox. You will need to ensure JavaScript is enabled within your browser's settings (this is normally enabled by default). JavaScript Syntax JavaScript syntax refers to a set of rules that determine how the language will be written (by the programmer) and interpreted (by the browser). The JavaScript syntax is loosely based on the Java syntax. Java is a full blown programming environment and JavaScript could be seen as a sub-set of the Java syntax. Having said this, that is where the similarities end - Java and JavaScript are two totally different things. In learning JavaScript you will become familiar with terms such as variables, functions, statements, operators, data types, objects etc. JavaScript Syntax – Con’t The tags tell the browser to expect a script in between them. You specify the language using the type attribute. The most popular scripting language on the web is JavaScript. The bits that look like HTML comments tag () are just that - HTML comment tags. These are optional but recommended. They tell browsers that don't support JavaScript (or with JavaScript disabled) to ignore the code in between. This prevents the code from being written out to your website users. The part that writes the actual text is only 1 line (document.write("JavaScript is not Java");). This is how you write text to a web page in JavaScript. This is an example of using a JavaScript function (also known as method). Where to put JavaScript? You can place your scripts in any of the following locations: Between the HTML document's head tags. Within the HTML document's body (i.e. between the body tags). In an external file (and link to it from your HTML document). - Inline Click Me! Internal document.getElementById("demo").innerHTML = "My First JavaScript"; External JavaScript Display: Writing into an HTML element, using innerHTML. document.getElementById("demo").innerHTML = 5 + 6; Writing into the HTML output using document.write(). document.write("Hello World"); Writing into an alert box, using window.alert(). window.alert(5 + 6); Writing into the browser console, using console.log(). console.log(5 + 6); JavaScript Statements JavaScript statements are composed of: Expressions, Values, Operators, Keywords, and Comments. 1. JavaScript variables are containers for storing data values. In this example, x, y, and z, are variables: var name = “CodersTrust”; var age = 5; var x = 10; var y = 20; var z = x + y ; var person = "John Doe", carName = "Volvo", price = 200; Naming Convention of Variable : Names can contain letters, digits, underscores, and dollar signs. Names must begin with a letter Names can also begin with $ and _ (but we will not use it in this tutorial) Names are case sensitive (y and Y are different variables) Reserved words (like JavaScript keywords) cannot be used as names Example 1: test1js.html JAVA SCRIPT Welcome to SMMTC This is HTML section.... window.alert("welcome to JavaScript!"); Example 1: test1js.html Example 2: test1js_onload.html JAVA SCRIPT function showText() { window.alert("welcome to JavaScript!"); } Welcome to SMMTC This is HTML section.... Example 2: test1js_onload.html Example 3: test1js_tab.html JAVA SCRIPT Tab Welcome to SMMTC Example of JavaScript.... function showHide(show, hide) { document.getElementById(show).style.display="block"; document.getElementById(hide).style.display="none"; } Example 3: cont… Tab 1 - Welcome to STIV3013 Tab 2 - WWW Programming Example 3: test1js_tab.html Example…. Example…. Example…. Add2no.html Output : JavaScript : Add Two. Numbers Using a Form and TextBox JavaScript : Add Two. Numbers Using a Form and TextBox JavaScript : Add Two. Numbers TextBox Using a Form and JavaScript :. Fahrenheit to Celcius JavaScript :. Fahrenheit to Celcius More…. Do refer JavaScript notes in pdf format in UOL Q& A QUESTION ANSWER