The document discusses various topics related to JavaScript including: announcing that code should not be posted in forums; creating folders for lectures and projects; an overview of JavaScript and how it can be used; details on strict mode; execution of JavaScript programs; basic constructs like variables, reserved words, spaces/semicolons/comments; and tools for beautifying and checking JavaScript code.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
59 views13 pages
005JSIntro Notes
The document discusses various topics related to JavaScript including: announcing that code should not be posted in forums; creating folders for lectures and projects; an overview of JavaScript and how it can be used; details on strict mode; execution of JavaScript programs; basic constructs like variables, reserved words, spaces/semicolons/comments; and tools for beautifying and checking JavaScript code.
Execution of JavaScript Programs • HTML parser Takes care of processing an html document • JavaScript interpreter Takes care of processing JavaScript code • HTML parser Must stop processing an html file when JavaScript code is found (JavaScript interpreter will then be running) – This implies a page with JavaScript code that is computationally intensive can take a long time to load
JavaScript • Let’s go over several basic constructs that allow us to define JavaScript programs • Some definitions – string Any set of characters in double quotes (“ “) – function/method • An entity that completes a particular task for us • It may take values necessary to complete the particular task • It can return values • Generating output with the document.writeln method – Allow us to add text to the html file (Example: Writeln.html) by providing the required text in “ “ – You can specify html code and results of JavaScript constructs
JavaScript • Example: Date.html • Illustrates how we can generate HMTL output • Notice how we can use Date() to specify a particular date format Date() is part of JavaScript • The + allow us to concatenate strings – Example: “Mary” + “Land” “MaryLand” – Example: “Time is: “ + new Date()
JavaScript (Variables) • Variable – A memory location that can store a value. In JavaScript variables are declared using var or let var temperature; let area; • We prefer let • Variables names must start with a letter, underscore or dollar sign and can be followed by any number of letters, underscores, dollar signs or digits • Variables must be declared before they are used • A variable can hold different type of values • Values we can assign to variables – Integer 0, 10, 40, 6, -7 – Floating-point 3.2, .67, 1.48E-20 – String literals “hello”, “goodbye” • Operators • Assignment operator (=) – Typical arithmetic operators (+, -, *, /) • Example: Variables.html
Spaces, Semicolons, and Comments • JavaScript ignores spaces, tabs, and newlines between tokens • Use spaces to create nicely indented code • The rules are usually one tab for indentation or three spaces. You need to satisfy this requirement in programming assignments • A semicolon is generally used to mark the end of a statement and is optional when a statement appears on a separate line. For example, the following two set of statements are equivalent x = 1; y = 2;
x=1 y=2 • In this course we will always use a semicolon to mark the end of a statement
Comments • Comments in JavaScript – Used to provide information to the programmer – Used to identify sections in your code – Ignored by the JavaScript interpreter • Two types of comments – Inline comment // This is a comment until the end of the line – Block comment /* The following is a comment that spans several lines */ – We can use a block comment for a single-line comment