This document provides an overview of JavaScript, including:
- JavaScript is not related to Java and was originally called LiveScript.
- JavaScript code is run in web browsers by an interpreter built into the browser, not on servers.
- JavaScript can be used to add interactivity to HTML pages by including <script> tags and running code when pages load or in response to user events.
- JavaScript functions and variables can be defined and used to manipulate the DOM and handle user interactions.
JavaScript was originally created as LiveScript in 1995 and renamed to JavaScript. It is an interpreted scripting language that can be added to HTML pages to provide dynamic interactivity. JavaScript code is executed by the browser's JavaScript engine and does not need to be compiled. It allows manipulating the structure, style, and content of HTML documents, validating form data, detecting browser capabilities, and much more.
This document provides an overview of JavaScript concepts for a course on developing web applications. It discusses JavaScript basics like using <script> tags, .js file extensions, and functions. It also covers if statements, commenting code, and embedding JavaScript directly in HTML or externally in .js files. The document then reviews DOM manipulation using the document object, variables, operators, and if statements. It provides examples of using onclick events to dynamically change HTML. Finally, it briefly introduces AJAX, cookies, and scoping in JavaScript functions.
This document outlines the objectives of a lecture on JavaScript. It introduces JavaScript, discusses data types, operators, flow control, functions, events, objects, arrays, and the Document Object Model. It provides examples of JavaScript concepts like functions, events, and objects. The document is intended to teach the basics of JavaScript programming.
This document outlines the objectives of a lecture on JavaScript. It will introduce JavaScript, including using script tags and linking external JavaScript files. It will cover JavaScript expressions, operators, functions, flow control, objects, arrays, the Document Object Model, forms, cookies and more. The lecture aims to provide an overview of the JavaScript language and how it is used for client-side scripting.
JavaScript is an object-oriented scripting language used to make webpages interactive. It is lightweight and commonly used as part of web pages. JavaScript can be used to validate user input, provide immediate feedback, and increase interactivity. JavaScript code can output data by writing to HTML elements, using alerts, or writing to the browser console. Key JavaScript concepts include variables, functions, objects, and arrays for storing and manipulating different types of data.
JavaScript was designed to add interactivity to HTML pages. It is a scripting language that is usually embedded directly into HTML pages and allows for dynamic text, event handling, reading/writing HTML elements, and validating form data. JavaScript supports both client-side and server-side scripting and was originally developed by Netscape under the name LiveScript before being renamed. It provides programming capabilities to HTML authors and allows for dynamic content, user interaction, and validation without server requests.
JavaScript allows for dynamic web pages and client-side form validation. It is embedded in HTML using <script> tags and can be stored in external .js files. Functions are commonly used in JavaScript. If/else statements and operators allow for conditional logic. AJAX enables asynchronous communication with servers. Cookies store small amounts of data in a user's browser.
- JavaScript code can be embedded in HTML files using <script> tags and is used to add dynamic and interactive behaviors to web pages. It is commonly used for form validation, dynamic HTML, and AJAX.
- Functions are commonly used in JavaScript to reuse code. Variables can be declared and used within functions and have limited scope. Operators, if/else statements, and loops allow for conditional logic.
- AJAX allows for asynchronous communication between the browser and server, improving interactivity. Cookies can be used to store small amounts of data on the client-side to remember information between requests.
This document provides an introduction to JavaScript, including what JavaScript is used for, how it interacts with HTML and CSS, and some basic JavaScript concepts. JavaScript allows making web pages interactive by inserting dynamic text, reacting to events like clicks, performing calculations, and getting information about the user's computer. It is commonly used for calculations, waiting for and responding to events, and manipulating HTML tags. The document discusses JavaScript's role on the client-side, using variables, data types, operators, arrays, functions, and the console for debugging. It provides examples of declaring variables, strings, logical operators, arrays, and functions.
The document contains the first 30 questions from a list of top 150 JavaScript interview questions. It covers topics like the differences between Java and JavaScript, data types in JavaScript, how to create arrays and objects, variable declaration keywords like var, let and const, and other fundamental concepts like functions, closures, promises and more.
This is the first part (out of two) about basics of JavaScript.
01 What is Dynamic HTML?
02 What is JavaScript?
03 How to JavaScript?
04 JavaScript Syntax
05 JavaScript Basics
06 Conditional Statements
JavaScript is a client-side scripting language that allows web pages to become interactive and dynamic. It can update and modify the content of an HTML page without needing to reload the page. JavaScript code can be embedded directly in HTML pages or placed in separate .js files. Common uses of JavaScript include validating form input, detecting the visitor's browser, creating cookies, and adding interactivity to HTML elements like buttons and links.
This document provides an introduction to JavaScript, covering topics such as:
- The scope of the lesson includes an introduction to JavaScript, using JavaScript code, syntax, data types, objects, strings, functions, and standard popup boxes.
- JavaScript is a client-side scripting language that allows interactivity on web pages by modifying HTML content and handling events. It is interpreted by web browsers rather than compiled.
- JavaScript code can be embedded directly in HTML, or linked via external .js files, and is executed when the page loads or in response to events.
JavaScript supports three primitive datatypes - numbers, strings, and booleans. It also supports objects as a composite datatype. Variables in JavaScript can hold values of any datatype and their type can change. Variables are declared with var and have either global or local scope depending on where they are defined. Variable names must start with a letter or underscore and cannot be reserved keywords.
It is a brief about JavaScript, To make understand the development and phases of development JavaScript.
It is helpful for beginner as well as intermediate level.
If you like it please comment or like for more updates.
Thanks
Java is an object-oriented programming language and platform. It uses a virtual machine (JVM) to run bytecode, making Java programs platform independent. The JVM handles memory management through garbage collection. Java uses classes and objects to implement OOP concepts. Variables are declared with a specific primitive data type or class type. Java supports control flow statements like if/else and loops. Arrays allow storing multiple values of the same type. Methods define reusable blocks of code that can operate on objects.
This document provides an overview of object-oriented programming fundamentals in Java, including basic concepts like objects, classes, inheritance, polymorphism, and encapsulation. It discusses Java features, the Java program structure, variables and data types, operators, expressions, arrays, and control statements. Object-oriented programming concepts like abstraction, encapsulation, inheritance and polymorphism are explained. The benefits and applications of OOP are also highlighted.
This document discusses jQuery selectors and DOM manipulation using jQuery. It begins with an introduction to jQuery, explaining that jQuery is a JavaScript library that simplifies HTML document traversal, event handling, animations and Ajax interactions. It then covers various jQuery selectors including element, ID, class and universal selectors. It provides examples of how to select and style elements using these selectors. The document also discusses jQuery's DOM manipulation methods for getting and setting attributes and traversing the DOM tree.
This document provides an introduction to JavaScript, including:
- JavaScript is a scripting language used primarily for client-side web development. It implements the ECMAScript standard.
- JavaScript can be used to create interactive user interfaces, dynamically manipulate web content, validate forms, and more.
- JavaScript code runs in the browser via JavaScript engines like V8, SpiderMonkey, and JavaScriptCore. It is interpreted at runtime rather than compiled.
The document discusses HTML5 semantic elements and how they can be used to structure web pages in a more transparent way compared to traditional <div> elements. It provides examples of common HTML5 semantic elements like <header>, <nav>, <article>, <section>, and <aside> that can be used instead of <div> for specific sections like navigation, headers, articles, etc. The document also briefly reviews common HTML4 elements like <html>, <head>, <title>, <body>, and heading elements to provide context before discussing the new HTML5 semantic elements.
JavaScript is the programming language of HTML and the Web.
JavaScript is easy to learn.
This Presentation will teach you JavaScript from basic to advanced.
This document provides an overview of JavaScript, including its uses, syntax, data types, operators, and objects. JavaScript is an object-based scripting language used to program the behavior of web pages. It allows for client-side validation, dynamic drop-down menus, displaying data and time, and other interactive effects. JavaScript code can be embedded directly in HTML using <script> tags or linked externally. The core data types include numbers, strings, Booleans, arrays, and objects. Objects are similar to arrays but use named indexes instead of numbered indexes. Key JavaScript concepts covered include variables, literals, functions, conditionals, and more.
JavaScript can change HTML content, attributes, styles, and validate data. It can be placed in the <body> and <head> sections between <script> tags. Functions and events allow JavaScript code to run when events occur. JavaScript can output to alerts, the document, elements, and the console. It uses data types like numbers, strings, Booleans, arrays, and objects. Conditionals like if/else and switch statements allow different code blocks to run based on conditions. Loops like for, for/in, while, and do/while repeat code.
Analysis of reinforced concrete deep beam is based on simplified approximate method due to the complexity of the exact analysis. The complexity is due to a number of parameters affecting its response. To evaluate some of this parameters, finite element study of the structural behavior of the reinforced self-compacting concrete deep beam was carried out using Abaqus finite element modeling tool. The model was validated against experimental data from the literature. The parametric effects of varied concrete compressive strength, vertical web reinforcement ratio and horizontal web reinforcement ratio on the beam were tested on eight (8) different specimens under four points loads. The results of the validation work showed good agreement with the experimental studies. The parametric study revealed that the concrete compressive strength most significantly influenced the specimens’ response with the average of 41.1% and 49 % increment in the diagonal cracking and ultimate load respectively due to doubling of concrete compressive strength. Although the increase in horizontal web reinforcement ratio from 0.31 % to 0.63 % lead to average of 6.24 % increment on the diagonal cracking load, it does not influence the ultimate strength and the load-deflection response of the beams. Similar variation in vertical web reinforcement ratio leads to an average of 2.4 % and 15 % increment in cracking and ultimate load respectively with no appreciable effect on the load-deflection response.
Ad
More Related Content
Similar to JavaScript ppt for introduction of javascripta (20)
JavaScript allows for dynamic web pages and client-side form validation. It is embedded in HTML using <script> tags and can be stored in external .js files. Functions are commonly used in JavaScript. If/else statements and operators allow for conditional logic. AJAX enables asynchronous communication with servers. Cookies store small amounts of data in a user's browser.
- JavaScript code can be embedded in HTML files using <script> tags and is used to add dynamic and interactive behaviors to web pages. It is commonly used for form validation, dynamic HTML, and AJAX.
- Functions are commonly used in JavaScript to reuse code. Variables can be declared and used within functions and have limited scope. Operators, if/else statements, and loops allow for conditional logic.
- AJAX allows for asynchronous communication between the browser and server, improving interactivity. Cookies can be used to store small amounts of data on the client-side to remember information between requests.
This document provides an introduction to JavaScript, including what JavaScript is used for, how it interacts with HTML and CSS, and some basic JavaScript concepts. JavaScript allows making web pages interactive by inserting dynamic text, reacting to events like clicks, performing calculations, and getting information about the user's computer. It is commonly used for calculations, waiting for and responding to events, and manipulating HTML tags. The document discusses JavaScript's role on the client-side, using variables, data types, operators, arrays, functions, and the console for debugging. It provides examples of declaring variables, strings, logical operators, arrays, and functions.
The document contains the first 30 questions from a list of top 150 JavaScript interview questions. It covers topics like the differences between Java and JavaScript, data types in JavaScript, how to create arrays and objects, variable declaration keywords like var, let and const, and other fundamental concepts like functions, closures, promises and more.
This is the first part (out of two) about basics of JavaScript.
01 What is Dynamic HTML?
02 What is JavaScript?
03 How to JavaScript?
04 JavaScript Syntax
05 JavaScript Basics
06 Conditional Statements
JavaScript is a client-side scripting language that allows web pages to become interactive and dynamic. It can update and modify the content of an HTML page without needing to reload the page. JavaScript code can be embedded directly in HTML pages or placed in separate .js files. Common uses of JavaScript include validating form input, detecting the visitor's browser, creating cookies, and adding interactivity to HTML elements like buttons and links.
This document provides an introduction to JavaScript, covering topics such as:
- The scope of the lesson includes an introduction to JavaScript, using JavaScript code, syntax, data types, objects, strings, functions, and standard popup boxes.
- JavaScript is a client-side scripting language that allows interactivity on web pages by modifying HTML content and handling events. It is interpreted by web browsers rather than compiled.
- JavaScript code can be embedded directly in HTML, or linked via external .js files, and is executed when the page loads or in response to events.
JavaScript supports three primitive datatypes - numbers, strings, and booleans. It also supports objects as a composite datatype. Variables in JavaScript can hold values of any datatype and their type can change. Variables are declared with var and have either global or local scope depending on where they are defined. Variable names must start with a letter or underscore and cannot be reserved keywords.
It is a brief about JavaScript, To make understand the development and phases of development JavaScript.
It is helpful for beginner as well as intermediate level.
If you like it please comment or like for more updates.
Thanks
Java is an object-oriented programming language and platform. It uses a virtual machine (JVM) to run bytecode, making Java programs platform independent. The JVM handles memory management through garbage collection. Java uses classes and objects to implement OOP concepts. Variables are declared with a specific primitive data type or class type. Java supports control flow statements like if/else and loops. Arrays allow storing multiple values of the same type. Methods define reusable blocks of code that can operate on objects.
This document provides an overview of object-oriented programming fundamentals in Java, including basic concepts like objects, classes, inheritance, polymorphism, and encapsulation. It discusses Java features, the Java program structure, variables and data types, operators, expressions, arrays, and control statements. Object-oriented programming concepts like abstraction, encapsulation, inheritance and polymorphism are explained. The benefits and applications of OOP are also highlighted.
This document discusses jQuery selectors and DOM manipulation using jQuery. It begins with an introduction to jQuery, explaining that jQuery is a JavaScript library that simplifies HTML document traversal, event handling, animations and Ajax interactions. It then covers various jQuery selectors including element, ID, class and universal selectors. It provides examples of how to select and style elements using these selectors. The document also discusses jQuery's DOM manipulation methods for getting and setting attributes and traversing the DOM tree.
This document provides an introduction to JavaScript, including:
- JavaScript is a scripting language used primarily for client-side web development. It implements the ECMAScript standard.
- JavaScript can be used to create interactive user interfaces, dynamically manipulate web content, validate forms, and more.
- JavaScript code runs in the browser via JavaScript engines like V8, SpiderMonkey, and JavaScriptCore. It is interpreted at runtime rather than compiled.
The document discusses HTML5 semantic elements and how they can be used to structure web pages in a more transparent way compared to traditional <div> elements. It provides examples of common HTML5 semantic elements like <header>, <nav>, <article>, <section>, and <aside> that can be used instead of <div> for specific sections like navigation, headers, articles, etc. The document also briefly reviews common HTML4 elements like <html>, <head>, <title>, <body>, and heading elements to provide context before discussing the new HTML5 semantic elements.
JavaScript is the programming language of HTML and the Web.
JavaScript is easy to learn.
This Presentation will teach you JavaScript from basic to advanced.
This document provides an overview of JavaScript, including its uses, syntax, data types, operators, and objects. JavaScript is an object-based scripting language used to program the behavior of web pages. It allows for client-side validation, dynamic drop-down menus, displaying data and time, and other interactive effects. JavaScript code can be embedded directly in HTML using <script> tags or linked externally. The core data types include numbers, strings, Booleans, arrays, and objects. Objects are similar to arrays but use named indexes instead of numbered indexes. Key JavaScript concepts covered include variables, literals, functions, conditionals, and more.
JavaScript can change HTML content, attributes, styles, and validate data. It can be placed in the <body> and <head> sections between <script> tags. Functions and events allow JavaScript code to run when events occur. JavaScript can output to alerts, the document, elements, and the console. It uses data types like numbers, strings, Booleans, arrays, and objects. Conditionals like if/else and switch statements allow different code blocks to run based on conditions. Loops like for, for/in, while, and do/while repeat code.
Analysis of reinforced concrete deep beam is based on simplified approximate method due to the complexity of the exact analysis. The complexity is due to a number of parameters affecting its response. To evaluate some of this parameters, finite element study of the structural behavior of the reinforced self-compacting concrete deep beam was carried out using Abaqus finite element modeling tool. The model was validated against experimental data from the literature. The parametric effects of varied concrete compressive strength, vertical web reinforcement ratio and horizontal web reinforcement ratio on the beam were tested on eight (8) different specimens under four points loads. The results of the validation work showed good agreement with the experimental studies. The parametric study revealed that the concrete compressive strength most significantly influenced the specimens’ response with the average of 41.1% and 49 % increment in the diagonal cracking and ultimate load respectively due to doubling of concrete compressive strength. Although the increase in horizontal web reinforcement ratio from 0.31 % to 0.63 % lead to average of 6.24 % increment on the diagonal cracking load, it does not influence the ultimate strength and the load-deflection response of the beams. Similar variation in vertical web reinforcement ratio leads to an average of 2.4 % and 15 % increment in cracking and ultimate load respectively with no appreciable effect on the load-deflection response.
its all about Artificial Intelligence(Ai) and Machine Learning and not on advanced level you can study before the exam or can check for some information on Ai for project
Concept of Problem Solving, Introduction to Algorithms, Characteristics of Algorithms, Introduction to Data Structure, Data Structure Classification (Linear and Non-linear, Static and Dynamic, Persistent and Ephemeral data structures), Time complexity and Space complexity, Asymptotic Notation - The Big-O, Omega and Theta notation, Algorithmic upper bounds, lower bounds, Best, Worst and Average case analysis of an Algorithm, Abstract Data Types (ADT)
In tube drawing process, a tube is pulled out through a die and a plug to reduce its diameter and thickness as per the requirement. Dimensional accuracy of cold drawn tubes plays a vital role in the further quality of end products and controlling rejection in manufacturing processes of these end products. Springback phenomenon is the elastic strain recovery after removal of forming loads, causes geometrical inaccuracies in drawn tubes. Further, this leads to difficulty in achieving close dimensional tolerances. In the present work springback of EN 8 D tube material is studied for various cold drawing parameters. The process parameters in this work include die semi-angle, land width and drawing speed. The experimentation is done using Taguchi’s L36 orthogonal array, and then optimization is done in data analysis software Minitab 17. The results of ANOVA shows that 15 degrees die semi-angle,5 mm land width and 6 m/min drawing speed yields least springback. Furthermore, optimization algorithms named Particle Swarm Optimization (PSO), Simulated Annealing (SA) and Genetic Algorithm (GA) are applied which shows that 15 degrees die semi-angle, 10 mm land width and 8 m/min drawing speed results in minimal springback with almost 10.5 % improvement. Finally, the results of experimentation are validated with Finite Element Analysis technique using ANSYS.
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...Infopitaara
A Boiler Feed Pump (BFP) is a critical component in thermal power plants. It supplies high-pressure water (feedwater) to the boiler, ensuring continuous steam generation.
⚙️ How a Boiler Feed Pump Works
Water Collection:
Feedwater is collected from the deaerator or feedwater tank.
Pressurization:
The pump increases water pressure using multiple impellers/stages in centrifugal types.
Discharge to Boiler:
Pressurized water is then supplied to the boiler drum or economizer section, depending on design.
🌀 Types of Boiler Feed Pumps
Centrifugal Pumps (most common):
Multistage for higher pressure.
Used in large thermal power stations.
Positive Displacement Pumps (less common):
For smaller or specific applications.
Precise flow control but less efficient for large volumes.
🛠️ Key Operations and Controls
Recirculation Line: Protects the pump from overheating at low flow.
Throttle Valve: Regulates flow based on boiler demand.
Control System: Often automated via DCS/PLC for variable load conditions.
Sealing & Cooling Systems: Prevent leakage and maintain pump health.
⚠️ Common BFP Issues
Cavitation due to low NPSH (Net Positive Suction Head).
Seal or bearing failure.
Overheating from improper flow or recirculation.
We introduce the Gaussian process (GP) modeling module developed within the UQLab software framework. The novel design of the GP-module aims at providing seamless integration of GP modeling into any uncertainty quantification workflow, as well as a standalone surrogate modeling tool. We first briefly present the key mathematical tools on the basis of GP modeling (a.k.a. Kriging), as well as the associated theoretical and computational framework. We then provide an extensive overview of the available features of the software and demonstrate its flexibility and user-friendliness. Finally, we showcase the usage and the performance of the software on several applications borrowed from different fields of engineering. These include a basic surrogate of a well-known analytical benchmark function; a hierarchical Kriging example applied to wind turbine aero-servo-elastic simulations and a more complex geotechnical example that requires a non-stationary, user-defined correlation function. The GP-module, like the rest of the scientific code that is shipped with UQLab, is open source (BSD license).
How to use nRF24L01 module with ArduinoCircuitDigest
Learn how to wirelessly transmit sensor data using nRF24L01 and Arduino Uno. A simple project demonstrating real-time communication with DHT11 and OLED display.
Fluid mechanics is the branch of physics concerned with the mechanics of fluids (liquids, gases, and plasmas) and the forces on them. Originally applied to water (hydromechanics), it found applications in a wide range of disciplines, including mechanical, aerospace, civil, chemical, and biomedical engineering, as well as geophysics, oceanography, meteorology, astrophysics, and biology.
It can be divided into fluid statics, the study of various fluids at rest, and fluid dynamics.
Fluid statics, also known as hydrostatics, is the study of fluids at rest, specifically when there's no relative motion between fluid particles. It focuses on the conditions under which fluids are in stable equilibrium and doesn't involve fluid motion.
Fluid kinematics is the branch of fluid mechanics that focuses on describing and analyzing the motion of fluids, such as liquids and gases, without considering the forces that cause the motion. It deals with the geometrical and temporal aspects of fluid flow, including velocity and acceleration. Fluid dynamics, on the other hand, considers the forces acting on the fluid.
Fluid dynamics is the study of the effect of forces on fluid motion. It is a branch of continuum mechanics, a subject which models matter without using the information that it is made out of atoms; that is, it models matter from a macroscopic viewpoint rather than from microscopic.
Fluid mechanics, especially fluid dynamics, is an active field of research, typically mathematically complex. Many problems are partly or wholly unsolved and are best addressed by numerical methods, typically using computers. A modern discipline, called computational fluid dynamics (CFD), is devoted to this approach. Particle image velocimetry, an experimental method for visualizing and analyzing fluid flow, also takes advantage of the highly visual nature of fluid flow.
Fundamentally, every fluid mechanical system is assumed to obey the basic laws :
Conservation of mass
Conservation of energy
Conservation of momentum
The continuum assumption
For example, the assumption that mass is conserved means that for any fixed control volume (for example, a spherical volume)—enclosed by a control surface—the rate of change of the mass contained in that volume is equal to the rate at which mass is passing through the surface from outside to inside, minus the rate at which mass is passing from inside to outside. This can be expressed as an equation in integral form over the control volume.
The continuum assumption is an idealization of continuum mechanics under which fluids can be treated as continuous, even though, on a microscopic scale, they are composed of molecules. Under the continuum assumption, macroscopic (observed/measurable) properties such as density, pressure, temperature, and bulk velocity are taken to be well-defined at "infinitesimal" volume elements—small in comparison to the characteristic length scale of the system, but large in comparison to molecular length scale
2. About JavaScript
• JavaScript is not Java, or even related to Java
– The original name for JavaScript was “LiveScript”
– The name was changed when Java became popular
• Statements in JavaScript resemble statements in Java,
because both languages borrowed heavily from the C
language
– JavaScript should be fairly easy for Java programmers to learn
– However, JavaScript is a complete, full-featured, complex language
• JavaScript is seldom used to write complete “programs”
– Instead, small bits of JavaScript are used to add functionality to
HTML pages
– JavaScript is often used in conjunction with HTML “forms”
• JavaScript is reasonably platform-independent
3. Using JavaScript in a browser
• JavaScript code is included within <script> tags:
– <script type="text/javascript">
document.write("<h1>Hello World!</h1>") ;
</script>
• Notes:
– The type attribute is to allow you to use other scripting languages
(but JavaScript is the default)
– This simple code does the same thing as just putting <h1>Hello
World!</h1> in the same place in the HTML document
– The semicolon at the end of the JavaScript statement is optional
• You need semicolons if you put two or more statements on the same
line
• It’s probably a good idea to keep using semicolons
4. Dealing with old browsers
• Some old browsers do not recognize script tags
– These browsers will ignore the script tags but will
display the included JavaScript
– To get old browsers to ignore the whole thing, use:
<script type="text/javascript">
<!--
document.write("Hello World!")
//-->
</script>
– The <!-- introduces an HTML comment
– To get JavaScript to ignore the HTML close comment, -->, the //
starts a JavaScript comment, which extends to the end of the line
5. Where to put JavaScript
• JavaScript can be put in the <head> or in the <body> of an
HTML document
– JavaScript functions should be defined in the <head>
• This ensures that the function is loaded before it is needed
– JavaScript in the <body> will be executed as the page loads
• JavaScript can be put in a separate .js file
– <script src="myJavaScriptFile.js"></script>
– Put this HTML wherever you would put the actual JavaScript code
– An external .js file lets you use the same JavaScript on multiple
HTML pages
– The external .js file cannot itself contain a <script> tag
• JavaScript can be put in HTML form object, such as a button
– This JavaScript will be executed when the form object is used
6. Primitive data types
• JavaScript has three “primitive” types: number, string,
and boolean
– Everything else is an object
• Numbers are always stored as floating-point values
– Hexadecimal numbers begin with 0x
– Some platforms treat 0123 as octal, others treat it as decimal
• Strings may be enclosed in single quotes or double quotes
– Strings can contains n (newline), " (double quote), etc.
• Booleans are either true or false
– 0, "0", empty strings, undefined, null, and NaN are false ,
other values are true
7. Variables
• Variables are declared with a var statement:
– var pi = 3.1416, x, y, name = "Dr. Dave" ;
– Variables names must begin with a letter or underscore
– Variable names are case-sensitive
– Variables are untyped (they can hold values of any type)
– The word var is optional (but it’s good style to use it)
• Variables declared within a function are local to
that function (accessible only within that function)
• Variables declared outside a function are global
(accessible from anywhere on the page)
8. Operators, I
• Because most JavaScript syntax is borrowed from C (and is
therefore just like Java), we won’t spend much time on it
• Arithmetic operators:
+ - * / % ++ --
• Comparison operators:
< <= == != >= >
• Logical operators:
&& || ! (&& and || are short-circuit operators)
• Bitwise operators:
& | ^ ~ << >> >>>
• Assignment operators:
+= -= *= /= %= <<= >>= >>>= &= ^= |=
9. Operators, II
• String operator:
+
• The conditional operator:
condition ? value_if_true : value_if_false
• Special equality tests:
– == and != try to convert their operands to the same type
before performing the test
– === and !== consider their operands unequal if they are
of different types
• Additional operators (to be discussed):
new typeof void delete
10. Comments
• Comments are as in C or Java:
– Between // and the end of the line
– Between /* and */
• Java’s javadoc comments, /** ... */, are treated
just the same as /* ... */ comments; they have no
special meaning in JavaScript
11. Statements, I
• Most JavaScript statements are also borrowed
from C
– Assignment: greeting = "Hello, " + name;
– Compound statement:
{ statement; ...; statement }
– If statements:
if (condition) statement;
if (condition) statement; else statement;
– Familiar loop statements:
while (condition) statement;
do statement while (condition);
for (initialization; condition; increment) statement;
12. Statements, II
• The switch statement:
switch (expression){
case label :
statement;
break;
case label :
statement;
break;
...
default : statement;
}
• Other familiar statements:
– break;
– continue;
– The empty statement, as in ;; or { }
13. JavaScript is not Java
• By now you should have realized that you already know a
great deal of JavaScript
– So far we have talked about things that are the same as in Java
• JavaScript has some features that resemble features in Java:
– JavaScript has Objects and primitive data types
– JavaScript has qualified names; for example,
document.write("Hello World");
– JavaScript has Events and event handlers
– Exception handling in JavaScript is almost the same as in Java
• JavaScript has some features unlike anything in Java:
– Variable names are untyped: the type of a variable depends on the
value it is currently holding
– Objects and arrays are defined in quite a different way
– JavaScript has with statements and a new kind of for statement
14. Exception handling, I
• Exception handling in JavaScript is almost the same as in
Java
• throw expression creates and throws an exception
– The expression is the value of the exception, and can be of any
type (often, it's a literal String)
• try {
statements to try
} catch (e) { // Notice: no type declaration for e
exception-handling statements
} finally { // optional, as usual
code that is always executed
}
– With this form, there is only one catch clause
15. Exception handling, II
• try {
statements to try
} catch (e if test1) {
exception-handling for the case that test1 is true
} catch (e if test2) {
exception-handling for when test1 is false and test2 is true
} catch (e) {
exception-handling for when both test1and test2 are false
} finally { // optional, as usual
code that is always executed
}
• Typically, the test would be something like
e == "InvalidNameException"
16. Object literals
• You don’t declare the types of variables in JavaScript
• JavaScript has object literals, written with this syntax:
– { name1 : value1 , ... , nameN : valueN }
• Example (from Netscape’s documentation):
– car = {myCar: "Saturn", 7: "Mazda",
getCar: CarTypes("Honda"), special: Sales}
• The fields are myCar, getCar, 7 (this is a legal field name) ,
and special
• "Saturn" and "Mazda" are Strings
• CarTypes is a function call
• Sales is a variable you defined earlier
– Example use: document.write("I own a " + car.myCar);
17. Three ways to create an object
• You can use an object literal:
– var course = { number: "CIT597", teacher="Dr. Dave" }
• You can use new to create a “blank” object, and add fields
to it later:
– var course = new Object();
course.number = "CIT597";
course.teacher = "Dr. Dave";
• You can write and use a constructor:
– function Course(n, t) { // best placed in <head>
this.number = n;
this.teacher = t;
}
– var course = new Course("CIT597", "Dr. Dave");
18. Array literals
• You don’t declare the types of variables in JavaScript
• JavaScript has array literals, written with brackets and
commas
– Example: color = ["red", "yellow", "green", "blue"];
– Arrays are zero-based: color[0] is "red"
• If you put two commas in a row, the array has an “empty”
element in that location
– Example: color = ["red", , , "green", "blue"];
• color has 5 elements
– However, a single comma at the end is ignored
• Example: color = ["red", , , "green", "blue”,]; still has 5 elements
19. Four ways to create an array
• You can use an array literal:
var colors = ["red", "green", "blue"];
• You can use new Array() to create an empty array:
– var colors = new Array();
– You can add elements to the array later:
colors[0] = "red"; colors[2] = "blue"; colors[1]="green";
• You can use new Array(n) with a single numeric
argument to create an array of that size
– var colors = new Array(3);
• You can use new Array(…) with two or more arguments
to create an array containing those values:
– var colors = new Array("red","green", "blue");
20. The length of an array
• If myArray is an array, its length is given by
myArray.length
• Array length can be changed by assignment beyond the
current length
– Example: var myArray = new Array(5); myArray[10] = 3;
• Arrays are sparse, that is, space is only allocated for
elements that have been assigned a value
– Example: myArray[50000] = 3; is perfectly OK
– But indices must be between 0 and 232
-1
• As in C and Java, there are no two-dimensional arrays; but
you can have an array of arrays: myArray[5][3]
21. Arrays and objects
• Arrays are objects
• car = { myCar: "Saturn", 7: "Mazda" }
– car[7] is the same as car.7
– car.myCar is the same as car["myCar"]
• If you know the name of a property, you can use
dot notation: car.myCar
• If you don’t know the name of a property, but you
have it in a variable (or can compute it), you must
use array notation: car.["my" + "Car"]
22. Array functions
• If myArray is an array,
– myArray.sort() sorts the array alphabetically
– myArray.sort(function(a, b) { return a - b; }) sorts
numerically
– myArray.reverse() reverses the array elements
– myArray.push(…) adds any number of new elements
to the end of the array, and increases the array’s length
– myArray.pop() removes and returns the last element
of the array, and decrements the array’s length
– myArray.toString() returns a string containing the
values of the array elements, separated by commas
23. The for…in statement
• You can loop through all the properties of an object with
for (variable in object) statement;
– Example: for (var prop in course) {
document.write(prop + ": " + course[prop]);
}
– Possible output: teacher: Dr. Dave
number: CIT597
– The properties are accessed in an undefined order
– If you add or delete properties of the object within the loop, it is
undefined whether the loop will visit those properties
– Arrays are objects; applied to an array, for…in will visit the
“properties” 0, 1, 2, …
– Notice that course["teacher"] is equivalent to course.teacher
• You must use brackets if the property name is in a variable
24. The with statement
• with (object) statement ; uses the object as the
default prefix for variables in the statement
• For example, the following are equivalent:
– with (document.myForm) {
result.value = compute(myInput.value) ;
}
– document.myForm.result.value =
compute(document.myForm.myInput.value);
• One of my books hints at mysterious problems
resulting from the use of with, and recommends
against ever using it
25. Functions
• Functions should be defined in the <head> of an
HTML page, to ensure that they are loaded first
• The syntax for defining a function is:
function name(arg1, …, argN) { statements }
– The function may contain return value; statements
– Any variables declared within the function are local to
it
• The syntax for calling a function is just
name(arg1, …, argN)
• Simple parameters are passed by value, objects are
passed by reference
26. Regular expressions
• A regular expression can be written in either of two ways:
– Within slashes, such as re = /ab+c/
– With a constructor, such as re = new RegExp("ab+c")
• Regular expressions are almost the same as in Perl or Java
(only a few unusual features are missing)
• string.match(regexp) searches string for an occurrence of
regexp
– It returns null if nothing is found
– If regexp has the g (global search) flag set, match returns an array
of matched substrings
– If g is not set, match returns an array whose 0th
element is the
matched text, extra elements are the parenthesized subexpressions,
and the index property is the start position of the matched
substring
27. Warnings
• JavaScript is a big, complex language
– We’ve only scratched the surface
– It’s easy to get started in JavaScript, but if you need to
use it heavily, plan to invest time in learning it well
– Write and test your programs a little bit at a time
• JavaScript is not totally platform independent
– Expect different browsers to behave differently
– Write and test your programs a little bit at a time
• Browsers aren’t designed to report errors
– Don’t expect to get any helpful error messages
– Write and test your programs a little bit at a time