Presentation is loading. Please wait.

Presentation is loading. Please wait.

JavaScript JavaScript Introduction. Q. What is JavaScript? Ans. JavaScript was designed to add interactivity to HTML pages. JavaScript is a scripting.

Similar presentations


Presentation on theme: "JavaScript JavaScript Introduction. Q. What is JavaScript? Ans. JavaScript was designed to add interactivity to HTML pages. JavaScript is a scripting."— Presentation transcript:

1 JavaScript JavaScript Introduction

2 Q. What is JavaScript? Ans. JavaScript was designed to add interactivity to HTML pages. JavaScript is a scripting language. A scripting language is a lightweight programming language. JavaScript is usually embedded directly into HTML pages. JavaScript is an interpreted language (means that scripts execute without preliminary compilation). Everyone can use JavaScript without purchasing a license. وقد تم تصميم جافا سكريبت لإضافة التفاعل إلى صفحات HTML جافا سكريبت هي لغة البرمجة لغة البرمجة هي لغة برمجة خفيفة وعادة ما يتم تضمين جافا سكريبت مباشرة في صفحات HTML جافا سكريبت هي لغة مفسرة ( يعني أن تنفيذ البرامج النصية دون تجميع أولي ) ويمكن للجميع استخدام جافا سكريبت دون شراء ترخيص

3 Q. Are Java and JavaScript is the same? Ans. NO! Java and JavaScript are two completely different languages in both concept and design! Java (developed by Sun Microsystems) is a powerful and much more complex programming language - in the same category as C and C++. لا ! جافا سكريبت وهما لغات مختلفة تماما في كل من مفهوم وتصميم ! جافا ( التي طورتها شركة صن مايكروسيستمز ) هي لغة برمجة قوية ومعقدة أكثر من ذلك بكثير -- في نفس فئة C و C + +.

4 Q. What is the use of JavaScript ? Ans. JavaScript gives HTML designers a programming tool. JavaScript can react to events. JavaScript can read and write HTML elements. JavaScript can be used to validate data. JavaScript can be used to detect the visitor's browser. JavaScript can be used to create cookies. جافا سكريبت يعطي المصممين HTML أداة البرمجة. يمكن أن تتفاعل مع الأحداث جافا سكريبت. جافا سكريبت يمكن القراءة والكتابة عناصر HTML. ويمكن استخدام جافا سكريبت للتحقق من صحة البيانات. ويمكن استخدام جافا سكريبت لكشف متصفح الزائر. ويمكن استخدام جافا سكريبت لإنشاء ملفات تعريف الارتباط.

5 Q. Is JavaScript is same as ECMAScript ? Ans. JavaScript is an implementation of the ECMAScript language standard. ECMA-262 is the official JavaScript standard. JavaScript was invented by Brendan Eich at Netscape (with Navigator 2.0), and has appeared in all browsers since 1996. The official standardization was adopted by the ECMA organization (an industry standardization association) in 1997.ECMA organization The ECMA standard (called ECMAScript-262) was approved as an international ISO (ISO/IEC 16262) standard in 1998. جافا سكريبت هو تنفيذ المعيار اللغة ECMAScript. ECMA - 262 هو المعيار جافا سكريبت الرسمية. اخترع جافا سكريبت التي برندان إيتش في نتسكيب ( مع المستكشف 2.0) ، وظهرت في جميع المتصفحات منذ عام 1996. اعتمد توحيد الرسمية التي يقوم بها تنظيم ECMA ( صناعة توحيد الجمعيات ) في عام 1997. تمت الموافقة على ECMA القياسية ( تسمى ECMAScript - 262) وايزو الدولية (ISO / IEC 16262) القياسية في عام 1998.

6 Q. How to write JavaScript into an HTML Page / Document? Examples Explained To insert a JavaScript into an HTML page, use the tag. Inside the tag use the type attribute to define the scripting language. The and tells where the JavaScript starts and ends. Sample Program My First Web Page This is a paragraph. document.getElementById("demo").innerHTML=Date(); The lines between the and contain the JavaScript and are executed by the browser. In this case the browser will replace the content of the HTML element with id="demo", with the current date.

7 Q. What is internal and external JavaScript? Ans. JavaScript can also be placed in external files. External JavaScript files often contain code to be used on several different web pages. External JavaScript files have the file extension.js. Note: External script cannot contain the tags! To use an external script, point to the.js file in the "src" attribute of the tag. ويمكن أيضا أن توضع في جافا سكريبت الملفات الخارجية. ملفات جافا سكريبت خارجية غالبا ما تحتوي على رمز ليتم استخدامه على عدة صفحات الويب المختلفة. الخارجية ملفات جافا سكريبت لديها ملحق الملف. شبيبة. ملاحظة : البرنامج النصي الخارجي لا يمكن أن تحتوي على العلامات ! لاستخدام برنامج نصي خارجية، وأشر إلى الملف شبيبة. في سمة " ضمني " للعلامة <<script and an Internal JavaScript which we seen in above code, that the HTML file having two tag …JavaScript Code….. Which means that we can place JavaScript code in- between two tag. Note:- JavaScripts can be put in the and in the sections of an HTML page.

8 JavaScript Functions and Events (Sample Program) The first program write date() when the page is loaded. My First Web Page This is a paragraph. document.getElementById("demo").innerHTML=Date(); In the second program when event occurs then it will show date. function displayDate() { document.getElementById("demo").innerHTML=Date(); } My First Web Page This is a paragraph. Display Date

9 JavaScript Comments, JavaScript Single line Comments Comments can be added to explain the JavaScript, or to make the code more readable. Single line comments start with //. Example:- // Write a heading document.write(" This is a heading "); // Write two paragraphs: document.write(" This is a paragraph. "); document.write(" This is another paragraph. "); JavaScript Multi-Line Comments Multi line comments start with /* and end with */. Example:- /* The code below will write one heading and two paragraphs */ document.write(" This is a heading "); Using Comments to Prevent Execution //document.write(" This is a heading "); …

10 JavaScript Variables You declare JavaScript variables with the var keyword. Like: var x; var Fname; // First method to assign a variable. Like: var x=10; var Fname=“Mohammad”// Assign a value to variable. It is case sensative. Variables are two types:- 1. Local JavaScript Variables:- A variable declared within a JavaScript function becomes LOCAL and can only be accessed within that function. (the variable has local scope). 2. Global JavaScript Variables:- Variables declared outside a function become GLOBAL, and all scripts and functions on the web page can access it.

11 JavaScript Operators Notes:- ( = is used to assign values, + is used to add values., The + Operator Used on Strings) Sample Program for operator) JavaScript Arithmetic Operators: (Given the result y=5) var x; x=5+5; document.write(x); document.write(" "); x="5"+"5"; document.write(x); document.write(" "); x=5+"5"; document.write(x); document.write(" "); x="5"+5; document.write(x); document.write(" "); The rule is: If you add a number and a string, the result will be a string. OperatorDescriptionExampleResult +AdditionX=y+2X=7Y=5 -SubtractionX=y-2X=3Y=5 *MultiplicationX=y*2X=10Y=5 /DivisionX=y/2X=2.5Y=5 %Modulus (division remainder)X=y%2X=1Y=5 ++IncrementX=y++ X=++y X=5 X=6 y=6 --DecrementX=y— X=--y X=5 X=4 Y=4

12 JavaScript Comparison and Logical Operators Comparison and Logical operators are used to test for true or false. Comparison Operators:- Given that x=5, the table below explains the comparison operators:- Logical Operators:- Given that x=6 and y=3, the table below. OperatorDescriptionExample ==Is equal toX==8 is false X==5 is true ===is exactly equal to (value and type)X===5 is true X===“5” is false !=Not equalX!=8 is true >Grater thanX>8 is false <Less thanX<8 is true >=Grater than or equal toX>=8 is false <=Less than or equal toX<=8 is true OperatorDescriptionExample &&and (x 1) is true ||Or x==5 || y==5) is false !Not (x==y) is true


Download ppt "JavaScript JavaScript Introduction. Q. What is JavaScript? Ans. JavaScript was designed to add interactivity to HTML pages. JavaScript is a scripting."

Similar presentations


Ads by Google