Download Chapter 2 - JavaScript Syntax and more Exercises Javascript programming in PDF only on Docsity! Chapter 2 - JavaScript Syntax JavaScript syntax refers to the set of rules that determine how JavaScript programs are built by the programmer and interpreted by the browser. <script>ā¦ā¦. </script> Html tag is use to implantation of JavaScript statements. You can place the <script> tags, which contain your JavaScript, anywhere on your web page, but it is usually recommended that you keep it in the <head> tags. Or we can add that <script> tag to the bottom of the file outside to the Html or in the <body> tag of the Html code. There are two ways to add JavaScript in HTML. 1. Embed JavaScript in HTML JavaScript code will be written as follows: <script> JavaScript Code </script> And the alternate way is 2. External JavaScript File This makes editing the code much easier for the programmer. āsrcā , ātypeā and ālanguageā are most common attributes of <script> tag. <script language =ājavascriptā src= āmy_file.jsā type= ātext/javascriptā> </script> Syntax Basics Understanding statements, variable naming, whitespace, and other basic JavaScript syntax. Variable Life Cycle Simple variable declaration B) Multi line Comment Semicolons JavaScript semicolons are optional. It does not strictly require semicolons. Case Sensitivity JavaScript is a case-sensitive language. This means that keywords, function names variables and any other identifiers must always be typed with a consistent capitalization of letters. For example: 1) The āreturnā keyword, must be typed āreturnā, not āReturnā or āRETURNā. 2) First JavaScript Code Let us take a simple example to print message āHello Worldā. Code 1)Put <script> into the head section. 2)Put <script> tag to the bottom of head section. Peel a ee) eee on seer es eee eat
rem nun
Pree nerne ea=2Reer)
DOCTYPE html
Sets gata Cd
Cire
irate
caetaee 7 cere
script:
Output
Ā© tye x + SL
SD Mile eyhservAmiyMocumenrs/evescipt/elle wordne| Qe Ā¢ eh 8
Hello World