The document discusses different types of program control statements in 3 categories: selection statements (if, switch), iteration statements (for, while, do-while, foreach), and jump statements (break, goto, continue, return, throw). It provides details on switch statements, including their general form and use of break. It also covers fallthrough in switch statements, which allows continuous execution of consecutive cases without break, and how to force fallthrough using goto. The document concludes with an overview of foreach loops, which iterate over an expression similar to for loops but do not allow changing the iteration variable.
This document provides information on processes, threads, concurrency, and parallelism in Java. It discusses that processes have separate memory spaces while threads within the same process share memory. It describes how to create threads by extending Thread or implementing Runnable. It also covers thread states, scheduling, priorities, and daemon threads.
This document provides an overview of client-server networking concepts in Java. It discusses elements like network basics, ports and sockets. It explains how to implement both TCP and UDP clients and servers in Java using socket classes. Sample code is provided for an echo client-server application using TCP and a quote client-server application using UDP. Exception handling for sockets is also demonstrated.
Fragments allow modularization of activities on larger screens like tablets. A fragment represents a behavior or UI portion and has its own lifecycle callbacks. Fragments can be placed in an activity layout via XML or added dynamically in code. Multiple fragments can be combined in a single activity to build a multi-pane UI. The activity lifecycle influences fragments, and fragments can be retained across configuration changes using setRetainInstance(true).
The document discusses application resources in Android. It covers externalizing resources from code, providing default and alternative resources for different configurations, and accessing resources in code and XML. Key points include placing resources in subdirectories under res/, specifying alternative resources using qualifiers like -hdpi, and referencing resources using IDs from the R class in code or XML syntax like @string/name.
String objects are immutable in Java, so any operation that modifies a String value actually creates a new String object. The StringBuffer and StringBuilder classes provide mutable alternatives to String that have similar methods but do not create new objects with each modification. When a String literal value is used in code, it is stored in the String constant pool to promote reuse of these immutable objects.
Este documento describe cómo crear una biblioteca dinámica (DLL) en C++ que realiza una operación matemática y muestra un mensaje de texto, y luego cómo llamar a esas funciones desde un proyecto de C# mediante DllImport. Se crea un proyecto DLL en C++ con funciones de suma y mensaje, se compila la DLL y se copia al proyecto de C# que muestra los resultados de llamar a esas funciones.
The document discusses different types of program control statements in 3 categories: selection statements (if, switch), iteration statements (for, while, do-while, foreach), and jump statements (break, goto, continue, return, throw). It provides details on switch statements, including their general form and use of break. It also covers fallthrough in switch statements, which allows continuous execution of consecutive cases without break, and how to force fallthrough using goto. The document concludes with an overview of foreach loops, which iterate over an expression similar to for loops but do not allow changing the iteration variable.
This document provides information on processes, threads, concurrency, and parallelism in Java. It discusses that processes have separate memory spaces while threads within the same process share memory. It describes how to create threads by extending Thread or implementing Runnable. It also covers thread states, scheduling, priorities, and daemon threads.
This document provides an overview of client-server networking concepts in Java. It discusses elements like network basics, ports and sockets. It explains how to implement both TCP and UDP clients and servers in Java using socket classes. Sample code is provided for an echo client-server application using TCP and a quote client-server application using UDP. Exception handling for sockets is also demonstrated.
Fragments allow modularization of activities on larger screens like tablets. A fragment represents a behavior or UI portion and has its own lifecycle callbacks. Fragments can be placed in an activity layout via XML or added dynamically in code. Multiple fragments can be combined in a single activity to build a multi-pane UI. The activity lifecycle influences fragments, and fragments can be retained across configuration changes using setRetainInstance(true).
The document discusses application resources in Android. It covers externalizing resources from code, providing default and alternative resources for different configurations, and accessing resources in code and XML. Key points include placing resources in subdirectories under res/, specifying alternative resources using qualifiers like -hdpi, and referencing resources using IDs from the R class in code or XML syntax like @string/name.
String objects are immutable in Java, so any operation that modifies a String value actually creates a new String object. The StringBuffer and StringBuilder classes provide mutable alternatives to String that have similar methods but do not create new objects with each modification. When a String literal value is used in code, it is stored in the String constant pool to promote reuse of these immutable objects.
Este documento describe cómo crear una biblioteca dinámica (DLL) en C++ que realiza una operación matemática y muestra un mensaje de texto, y luego cómo llamar a esas funciones desde un proyecto de C# mediante DllImport. Se crea un proyecto DLL en C++ con funciones de suma y mensaje, se compila la DLL y se copia al proyecto de C# que muestra los resultados de llamar a esas funciones.
Regular Expressions 101 Introduction to Regular ExpressionsDanny Bryant
This document discusses regular expressions and provides examples of using regular expression functions in SQL. It begins with an introduction to regular expressions and meta characters. It then demonstrates the REGEXP_LIKE, REGEXP_REPLACE, REGEXP_INSTR, REGEXP_SUBSTR, and REGEXP_COUNT functions with examples. The document is presented by Danny Bryant, an IT manager at the City of Atlanta.
The document discusses JUnit 5, the next generation of the JUnit testing framework for Java. Key aspects include a new programming model using extensions, support for Java 8 features, and ways to migrate from earlier JUnit versions. The new framework consists of the JUnit Platform launcher, the JUnit Jupiter API for writing tests, and the JUnit Vintage engine for running JUnit 3 and 4 tests.
This document provides an introduction to XML Path Language (XPath), which is a syntax for locating information in an XML document. It describes the different node types in an XML document and XPath tree, such as element nodes, attribute nodes, and text nodes. It also explains some basic XPath concepts like axes, node tests, and location paths that allow navigating the XPath tree using steps separated by axes and node tests. Some examples of XPath functions and operators for manipulating node sets returned from location paths are also presented. Finally, it provides sample XML documents and uses XPath to select nodes and extract information from them.
SQL is a standard language for accessing and manipulating databases. It allows users to retrieve, insert, update, and delete data as well as create new databases and tables. Common SQL statements include SELECT, UPDATE, DELETE, and INSERT. SQL uses clauses, operators, and wildcards to filter records based on conditions. Some key points are that SQL is an ANSI standard but different versions exist, it allows querying and modifying data in databases, and is essential for interacting with relational database systems.
The Collections Framework (java.util)- Collections overview, Collection Interfaces, The Collection classes- Array List, Linked List, Hash Set, Tree Set, Priority Queue, Array Deque. Accessing a Collection via an Iterator, Using an Iterator, The For-Each alternative, Map Interfaces and Classes, Comparators, Collection algorithms, Arrays, The Legacy Classes and Interfaces- Dictionary, Hashtable ,Properties, Stack, Vector More Utility classes, String Tokenizer, Bit Set, Date, Calendar, Random, Formatter, Scanner
This document discusses JavaScript events. It defines an event as an action a script can respond to, such as clicks or keystrokes. Event handlers are functions assigned to events that run when the event occurs. Events follow a cycle of capturing, targeting, and bubbling. Common event types include mouse, keyboard, loading, selection, and other events. The document provides examples of using event handlers with buttons, images, and adding/removing event listeners.
This document provides an overview and introduction to PLY, a Python implementation of lex and yacc parsing tools. PLY allows writing parsers and compilers in Python by providing modules that handle lexical analysis (ply.lex) and parsing (ply.yacc) in a similar way to traditional lex and yacc tools. The document demonstrates how to define tokens and grammar rules with PLY and discusses why PLY is useful for building parsers and compilers in Python.
Looping statements in PHP include the while, do-while, for, and foreach loops. The while loop checks the condition first before iterating, while the do-while loop checks after iterating. The for loop is used when the number of iterations is known in advance. It initializes, checks a condition, and increments between iterations. The foreach loop iterates over arrays, allowing access to both values and keys. The break statement exits the current loop, while continue skips to the next iteration.
The document shows how to perform polynomial regression in Python and R. It imports data on position level and salary. Linear and polynomial regression models are fit to predict salary from position level. Visualizations are created to compare the linear and polynomial regression fits and predictions. Polynomial regression fits the data better by capturing the nonlinear relationship between position level and salary.
Procedures in pl/sql,CREATE PROCEDURE Syntax, Compiling and Showing Errors, Parameters, Defining the IN, OUT, and IN OUT Parameter Modes, Parameter Constraint Restrictions, Example – Procedure with No Parameters,Example – Passing IN and OUT Parameters, Dropping a Procedure
The document discusses functions in C programming. The key points are:
1. A function is a block of code that performs a specific task. Functions allow code reusability and modularity.
2. main() is the starting point of a C program where execution begins. User-defined functions are called from main() or other functions.
3. Functions can take arguments and return values. There are different ways functions can be defined based on these criteria.
4. Variables used within a function have local scope while global variables can be accessed from anywhere. Pointers allow passing arguments by reference.
The document discusses structures in C programming. It defines structures as a way to pack together logically related data items of different types. Some key points:
- Structures allow defining custom data types that group together members of integer, float, character, and other standard types.
- Structure variables are declared and members accessed using the dot operator. Arrays of structures can also be defined.
- Structures can be initialized in various ways and passed to functions by value or by reference.
- Nested structures, where one structure is defined as a member of another, are also supported.
The document also covers arrays of structures, passing structures to functions, user-defined data types using typedef and enums,
1. Overview
1.1 What is a web service?
1.2 What is a web service?(cont.)
2. Working with SOAP services
2.1 What is SOAP?
2.2 What is SOAP? (cont.)
2.3 Why is SOAP Needed?
2.4 SOAP Building Blocks
2.5 SOAP Building Blocks (cont.)
3. Working with XML
3.1 What is XML?
3.2 What is XML Parser?
3.3 The main types of parsers?
3.4 What is SAX parser?
3.5 What is SAX parser? (cont.)
3.6 What is DOM parser?
3.7 What is DOM parser? (cont.)
3.8 What is Pull parser?
3.9 What is Pull parser? (cont.)
4. Using KSoap2 Library
4.1 What is KSoap2?
4.2 Why is KSoap2 Needed?
5. Working with Restful web services
6. Working with JSON
6.1 What is JSON?
6.2 JSON’s basic types
Java Cheat Sheet includes the following contents:
- Data Types
- Statements
- String, ArrayList and HashMap Methods
- Conversion
- Operators
- Exception Handling
Pointers in C allow programs to store and manipulate memory addresses. The document explains that pointers store the address of another variable in memory and use dereferencing operators like * to access the value at that address. It demonstrates how to declare and assign pointers, pass pointers to functions, and use pointer arithmetic to traverse arrays. Key concepts covered include address-of & and dereference * operators, double pointers, and how modifying a pointer or value it points to changes the referenced memory location.
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)Make Mannan
This document provides a lab manual for experiments on data structures. It includes 20 experiments covering topics like arrays, matrices, recursion, strings, stacks, queues, linked lists, trees, graphs and sorting algorithms. Each experiment contains the aim, introduction, source code, sample output and questions. The experiments provide hands-on practice with commonly used data structures and algorithms.
The program accepts 5 items from the command line and stores them in a Vector. It then demonstrates deleting an item, adding an item at a specified position, adding an item at the end, and printing the Vector contents. The Vector implements a dynamic array that can hold any type of objects and any number of elements. It is contained in the java.util package and is synchronized.
This document provides an overview of MySQL, a relational database management system that uses SQL. It discusses the different languages used in SQL - Data Definition Language (DDL) for creating and modifying database objects, Data Manipulation Language (DML) for inserting, updating, selecting and deleting data, Data Control Language (DCL) for granting and revoking user privileges, and Transaction Control Language (TCL) for managing transactions. Each section provides examples of key commands used for each language type and their purposes.
This document provides an overview of C# programming basics, including:
- C# is an object-oriented language where the basic unit is a class containing methods and variables.
- A C# program consists of at least one class that must contain a Main method, which acts as the program entry point.
- The document discusses basic C# concepts like variables, data types, operators, conditional statements, loops, methods, and arrays.
- It also covers how to compile and run a simple "Hello World" C# program, and provides examples of different programming constructs.
This document discusses structures and unions in C++. It defines a structure as a collection of related data items of different types stored together in memory. Structures allow defining custom data types that group various member variables. Unions also define custom data types but allow different types of variables to share the same memory space, taking up only as much space as its largest member. The document provides examples of declaring, defining, initializing, accessing members, and using structures and unions in C++ programs. It also compares the key differences between structures and unions.
JavaScript is a dynamic programming language used widely in web pages. It allows client-side scripts to interact with users and dynamically update pages. JavaScript code can be placed within <script> tags in HTML pages or external .js files. Common uses of JavaScript include basic arithmetic, variables, functions, objects, arrays, conditional logic, and DOM manipulation. Key JavaScript concepts covered in the document include data types, operators, variables, functions, objects, arrays, conditional statements, and the Date object.
This document provides an outline and overview of client-side technologies including JavaScript, DOM, and jQuery. The outline covers JavaScript concepts like data types, control structures, arrays, functions, and objects. It also covers DOM levels and manipulating the DOM. Finally, it discusses jQuery and how to load, select elements, handle events, and more. The presentation aims to familiarize students with these important front-end technologies.
Regular Expressions 101 Introduction to Regular ExpressionsDanny Bryant
This document discusses regular expressions and provides examples of using regular expression functions in SQL. It begins with an introduction to regular expressions and meta characters. It then demonstrates the REGEXP_LIKE, REGEXP_REPLACE, REGEXP_INSTR, REGEXP_SUBSTR, and REGEXP_COUNT functions with examples. The document is presented by Danny Bryant, an IT manager at the City of Atlanta.
The document discusses JUnit 5, the next generation of the JUnit testing framework for Java. Key aspects include a new programming model using extensions, support for Java 8 features, and ways to migrate from earlier JUnit versions. The new framework consists of the JUnit Platform launcher, the JUnit Jupiter API for writing tests, and the JUnit Vintage engine for running JUnit 3 and 4 tests.
This document provides an introduction to XML Path Language (XPath), which is a syntax for locating information in an XML document. It describes the different node types in an XML document and XPath tree, such as element nodes, attribute nodes, and text nodes. It also explains some basic XPath concepts like axes, node tests, and location paths that allow navigating the XPath tree using steps separated by axes and node tests. Some examples of XPath functions and operators for manipulating node sets returned from location paths are also presented. Finally, it provides sample XML documents and uses XPath to select nodes and extract information from them.
SQL is a standard language for accessing and manipulating databases. It allows users to retrieve, insert, update, and delete data as well as create new databases and tables. Common SQL statements include SELECT, UPDATE, DELETE, and INSERT. SQL uses clauses, operators, and wildcards to filter records based on conditions. Some key points are that SQL is an ANSI standard but different versions exist, it allows querying and modifying data in databases, and is essential for interacting with relational database systems.
The Collections Framework (java.util)- Collections overview, Collection Interfaces, The Collection classes- Array List, Linked List, Hash Set, Tree Set, Priority Queue, Array Deque. Accessing a Collection via an Iterator, Using an Iterator, The For-Each alternative, Map Interfaces and Classes, Comparators, Collection algorithms, Arrays, The Legacy Classes and Interfaces- Dictionary, Hashtable ,Properties, Stack, Vector More Utility classes, String Tokenizer, Bit Set, Date, Calendar, Random, Formatter, Scanner
This document discusses JavaScript events. It defines an event as an action a script can respond to, such as clicks or keystrokes. Event handlers are functions assigned to events that run when the event occurs. Events follow a cycle of capturing, targeting, and bubbling. Common event types include mouse, keyboard, loading, selection, and other events. The document provides examples of using event handlers with buttons, images, and adding/removing event listeners.
This document provides an overview and introduction to PLY, a Python implementation of lex and yacc parsing tools. PLY allows writing parsers and compilers in Python by providing modules that handle lexical analysis (ply.lex) and parsing (ply.yacc) in a similar way to traditional lex and yacc tools. The document demonstrates how to define tokens and grammar rules with PLY and discusses why PLY is useful for building parsers and compilers in Python.
Looping statements in PHP include the while, do-while, for, and foreach loops. The while loop checks the condition first before iterating, while the do-while loop checks after iterating. The for loop is used when the number of iterations is known in advance. It initializes, checks a condition, and increments between iterations. The foreach loop iterates over arrays, allowing access to both values and keys. The break statement exits the current loop, while continue skips to the next iteration.
The document shows how to perform polynomial regression in Python and R. It imports data on position level and salary. Linear and polynomial regression models are fit to predict salary from position level. Visualizations are created to compare the linear and polynomial regression fits and predictions. Polynomial regression fits the data better by capturing the nonlinear relationship between position level and salary.
Procedures in pl/sql,CREATE PROCEDURE Syntax, Compiling and Showing Errors, Parameters, Defining the IN, OUT, and IN OUT Parameter Modes, Parameter Constraint Restrictions, Example – Procedure with No Parameters,Example – Passing IN and OUT Parameters, Dropping a Procedure
The document discusses functions in C programming. The key points are:
1. A function is a block of code that performs a specific task. Functions allow code reusability and modularity.
2. main() is the starting point of a C program where execution begins. User-defined functions are called from main() or other functions.
3. Functions can take arguments and return values. There are different ways functions can be defined based on these criteria.
4. Variables used within a function have local scope while global variables can be accessed from anywhere. Pointers allow passing arguments by reference.
The document discusses structures in C programming. It defines structures as a way to pack together logically related data items of different types. Some key points:
- Structures allow defining custom data types that group together members of integer, float, character, and other standard types.
- Structure variables are declared and members accessed using the dot operator. Arrays of structures can also be defined.
- Structures can be initialized in various ways and passed to functions by value or by reference.
- Nested structures, where one structure is defined as a member of another, are also supported.
The document also covers arrays of structures, passing structures to functions, user-defined data types using typedef and enums,
1. Overview
1.1 What is a web service?
1.2 What is a web service?(cont.)
2. Working with SOAP services
2.1 What is SOAP?
2.2 What is SOAP? (cont.)
2.3 Why is SOAP Needed?
2.4 SOAP Building Blocks
2.5 SOAP Building Blocks (cont.)
3. Working with XML
3.1 What is XML?
3.2 What is XML Parser?
3.3 The main types of parsers?
3.4 What is SAX parser?
3.5 What is SAX parser? (cont.)
3.6 What is DOM parser?
3.7 What is DOM parser? (cont.)
3.8 What is Pull parser?
3.9 What is Pull parser? (cont.)
4. Using KSoap2 Library
4.1 What is KSoap2?
4.2 Why is KSoap2 Needed?
5. Working with Restful web services
6. Working with JSON
6.1 What is JSON?
6.2 JSON’s basic types
Java Cheat Sheet includes the following contents:
- Data Types
- Statements
- String, ArrayList and HashMap Methods
- Conversion
- Operators
- Exception Handling
Pointers in C allow programs to store and manipulate memory addresses. The document explains that pointers store the address of another variable in memory and use dereferencing operators like * to access the value at that address. It demonstrates how to declare and assign pointers, pass pointers to functions, and use pointer arithmetic to traverse arrays. Key concepts covered include address-of & and dereference * operators, double pointers, and how modifying a pointer or value it points to changes the referenced memory location.
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)Make Mannan
This document provides a lab manual for experiments on data structures. It includes 20 experiments covering topics like arrays, matrices, recursion, strings, stacks, queues, linked lists, trees, graphs and sorting algorithms. Each experiment contains the aim, introduction, source code, sample output and questions. The experiments provide hands-on practice with commonly used data structures and algorithms.
The program accepts 5 items from the command line and stores them in a Vector. It then demonstrates deleting an item, adding an item at a specified position, adding an item at the end, and printing the Vector contents. The Vector implements a dynamic array that can hold any type of objects and any number of elements. It is contained in the java.util package and is synchronized.
This document provides an overview of MySQL, a relational database management system that uses SQL. It discusses the different languages used in SQL - Data Definition Language (DDL) for creating and modifying database objects, Data Manipulation Language (DML) for inserting, updating, selecting and deleting data, Data Control Language (DCL) for granting and revoking user privileges, and Transaction Control Language (TCL) for managing transactions. Each section provides examples of key commands used for each language type and their purposes.
This document provides an overview of C# programming basics, including:
- C# is an object-oriented language where the basic unit is a class containing methods and variables.
- A C# program consists of at least one class that must contain a Main method, which acts as the program entry point.
- The document discusses basic C# concepts like variables, data types, operators, conditional statements, loops, methods, and arrays.
- It also covers how to compile and run a simple "Hello World" C# program, and provides examples of different programming constructs.
This document discusses structures and unions in C++. It defines a structure as a collection of related data items of different types stored together in memory. Structures allow defining custom data types that group various member variables. Unions also define custom data types but allow different types of variables to share the same memory space, taking up only as much space as its largest member. The document provides examples of declaring, defining, initializing, accessing members, and using structures and unions in C++ programs. It also compares the key differences between structures and unions.
JavaScript is a dynamic programming language used widely in web pages. It allows client-side scripts to interact with users and dynamically update pages. JavaScript code can be placed within <script> tags in HTML pages or external .js files. Common uses of JavaScript include basic arithmetic, variables, functions, objects, arrays, conditional logic, and DOM manipulation. Key JavaScript concepts covered in the document include data types, operators, variables, functions, objects, arrays, conditional statements, and the Date object.
This document provides an outline and overview of client-side technologies including JavaScript, DOM, and jQuery. The outline covers JavaScript concepts like data types, control structures, arrays, functions, and objects. It also covers DOM levels and manipulating the DOM. Finally, it discusses jQuery and how to load, select elements, handle events, and more. The presentation aims to familiarize students with these important front-end technologies.
This document provides an outline and overview of client-side technologies including JavaScript, DOM, and jQuery. The outline includes sections on JavaScript concepts like data types, control structures, arrays, functions, and objects. It also covers DOM levels and manipulating the DOM, as well as introductions to jQuery for selecting elements, changing styles, and handling events. The presentation provides an overview of these key client-side technologies for students.
JavaScript is one of three core web technologies that developers must learn, along with HTML and CSS. It allows for dynamic interactions and programming of web page behavior. JavaScript code can be placed in the head or body of an HTML document, or in external files. It uses variables, operators, functions and can access and modify HTML elements using the DOM (Document Object Model).
JavaScript is one of three core web programming languages that all developers must learn, along with HTML and CSS. JavaScript code can be inserted into HTML documents using <script> tags and can be placed in the <head> or <body> sections. JavaScript functions and code can also be stored in external .js files and referenced using <script> tags. JavaScript provides various ways to display and output data, including writing to HTML elements using innerHTML, displaying popup alerts, writing to the browser console, and more.
JavaScript is the primary scripting language of the web and is used to make web pages interactive. It can dynamically write and modify HTML content, react to user events like clicks, validate form data, detect the browser, and more. JavaScript code is commonly embedded directly in HTML using <script> tags and can also be stored externally in .js files. Key JavaScript concepts include variables, operators, conditional statements, functions, loops, and events.
JavaScript is a scripting language that adds interactivity to HTML pages. It can be used to dynamically write text, react to events, read and write HTML elements, validate data, detect the visitor's browser, and create cookies. JavaScript code can be placed in the head or body sections of an HTML page and is usually embedded directly into HTML pages. External JavaScript files can also be used to run the same code on multiple pages.
JavaScript is the most popular scripting language used on web pages. It can be used to add interactivity and dynamic content to HTML pages. JavaScript code can be embedded directly in HTML pages or stored externally in .js files. JavaScript code can be placed in the <head> or <body> sections of an HTML page. Common JavaScript statements include conditional statements like if/else, loops like for and while loops, and functions. JavaScript also provides popup boxes like alert, confirm, and prompt to interact with users.
This document provides an overview of JavaScript for client-side programming. It discusses how JavaScript code can be embedded in HTML pages using <script> tags and executed as the page loads. The document covers JavaScript data types, variables, operators, control structures, functions, and libraries. Functions allow code reuse and modularity. Libraries of useful functions can be stored in separate files and loaded as needed.
1. JavaScript can be used to program the behavior of web pages by changing HTML content and styles, hiding and showing HTML elements, and writing output in different ways.
2. JavaScript uses variables to store and work with data values. Variables are declared with var and assigned values using the equal sign.
3. JavaScript statements are made up of expressions, operators, and variables to perform actions like assigning values, performing calculations, and writing output.
This document provides an introduction and overview of JavaScript. It begins with an explanation of what dynamic HTML (DHTML) is and its key technologies including HTML, CSS, JavaScript, and the DOM. It then discusses what JavaScript is, its advantages, and what it can do. The document outlines how JavaScript code can be implemented in web pages and describes basic JavaScript syntax including variables, data types, operators, and conditional and loop statements. It provides examples of JavaScript functions, events, and interacting with HTML elements.
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 allows interactive content on web pages and control of the browser and document. It is an interpreted scripting language that is cross-platform but support varies. Javascript can provide interactive content, control document appearance and content, and interact with the user through event handlers.
MYSQL DATABASE INTRODUCTION TO JAVASCRIPT.pptxArjayBalberan1
This document provides an introduction to JavaScript, including:
- Why use client-side scripting with JavaScript in addition to server-side PHP. JavaScript allows for faster user interfaces, more efficient page updates, and event-driven interactions.
- What JavaScript is - a lightweight scripting language used to make web pages interactive by inserting dynamic text, reacting to events, and performing calculations in the browser.
- Key differences between JavaScript and other languages like Java and PHP in terms of being interpreted vs compiled, syntax, and where code runs.
- How JavaScript uses event-driven programming in response to user actions rather than starting with a main method.
- The Document Object Model (DOM) which allows JavaScript to access
The document provides an overview of topics covered in a lecture on fundamentals of computer systems, including logic, Boolean algebra, memory concepts, file management, databases, cyber security, data modeling, algorithms, JavaScript, HTML structure, and adding JavaScript to web pages. It discusses placing JavaScript in the head or body of an HTML document and linking external JavaScript files. It also covers JavaScript statements, comments, variables, data types, arithmetic operators, comparison operators, and arrays.
This document provides an introduction to JavaScript and covers topics such as:
- JavaScript allows for interactivity on web pages by manipulating the browser and reacting to user actions.
- JavaScript code is embedded within HTML pages and executed on the client-side by the browser.
- Common JavaScript concepts covered include variables, functions, scope, events, and form validation.
- JavaScript can be used to validate user input, perform calculations, and modify the DOM in response to events.
The document provides background information on HTML, JavaScript, CSS, and their relationships. It discusses how SGML led to the creation of HTML by Tim Berners-Lee as a subset of SGML. Cascading Style Sheets (CSS) were later created to separate document structure from presentation. Extensible Markup Language (XML) further separated content from style. The document also covers the evolution of HTML versions and the creation of XHTML.
Similar to FYBSC IT Web Programming Unit III Javascript (20)
Data Security and Privacy:
Introduction to Data Security: Importance, common security threats.
Data Privacy: Privacy concerns in the digital age, protecting personal information online.
Introduction to Computer Fundamentals:
Overview of Computer Fundamentals: Definition, importance, and evolution of computers.
Computer Hardware: Central Processing Unit (CPU), memory (RAM and ROM), input and output devices, storage devices.
Computer Software: Operating systems, application software, programming languages. Computer Applications in psychology
Computer Ethics and Emerging Technologies:
Computer Ethics: Ethical considerations in computer usage, intellectual property rights, and plagiarism.
Emerging Technologies: Artificial Intelligence (AI), Internet of Things (IoT), Blockchain Technology.
Introduction to Computer Fundamentals:
Overview of Computer Fundamentals: Definition, importance, and evolution of computers.
Computer Hardware: Central Processing Unit (CPU), memory (RAM and ROM), input and output devices, storage devices.
Computer Software: Operating systems, application software, programming languages. Computer Applications in Healthcare
Computer Networks and Internet Basics:
Computer Networks: Introduction to networks, types of networks (LAN, WAN, WLAN), network topologies.
Networking Basics: Network components (routers, switches, hubs), IP addressing (IPv4, IPv6), TCP/IP Protocol.
Internet and World Wide Web: Understanding the Internet, web browsers, search engines, online research techniques.
The document discusses operating systems and software applications. It provides an overview of operating systems, including their functions, types, popular systems like Windows, macOS and Linux, and user interfaces. It describes file management with file systems, directory structures and common file operations. Key software applications are also mentioned like word processing, spreadsheets, presentations and databases.
Bioinformatics: Bioinformatics, Healthcare Informatics and Analytics for Improved Healthcare System, Intelligent Monitoring and Control for Improved Healthcare System.
Protocols and Evidence based Healthcare: information technology tools to support best practices in health care, information technology tools that inform and empower patients.
Clinical Decision Support Systems: Making Decisions, the impact health information technology on the delivery of care in a rapidly changing healthcare marketplace.
Design and Evaluation of Information Systems and Services: principles of designing information systems, strategies for Information system evaluation, Information Systems Effectiveness Measures.
This document provides information on quality improvement strategies, protocols, and evidence-based healthcare. It discusses principles of designing information systems and strategies for evaluating them. It also covers quality improvement tools like the PDCA cycle and factors that help create and sustain healthcare informatics as a new field. The learning objectives are outlined on quality improvement tools, factors to create healthcare informatics, and understanding the PDCA cycle. The introduction defines quality and different approaches to defining it. Six criteria for right healthcare are also mentioned.
Information Privacy and Security: The Value and Importance of Health Information Privacy, security of health data, potential technical approaches to health data privacy and security.
Electronic Health Records: purpose of electronic health records, popular electronic health record system, advantages of electronic records, challenges of electronic health records, the key players involved.
Overview of Health Informatics: survey of fundamentals of health information technology, Identify the forces behind health informatics, educational and career opportunities in health informatics.
Information System Acquisition & Lifecycle: system acquisition process, phases: Initiation, Planning, Procurement, System Development, System Implementation, Maintenance & Operations, and Closeout. development models.
বাংলাদেশের অর্থনৈতিক সমীক্ষা ২০২৪ [Bangladesh Economic Review 2024 Bangla.pdf] কম্পিউটার , ট্যাব ও স্মার্ট ফোন ভার্সন সহ সম্পূর্ণ বাংলা ই-বুক বা pdf বই " সুচিপত্র ...বুকমার্ক মেনু 🔖 ও হাইপার লিংক মেনু 📝👆 যুক্ত ..
আমাদের সবার জন্য খুব খুব গুরুত্বপূর্ণ একটি বই ..বিসিএস, ব্যাংক, ইউনিভার্সিটি ভর্তি ও যে কোন প্রতিযোগিতা মূলক পরীক্ষার জন্য এর খুব ইম্পরট্যান্ট একটি বিষয় ...তাছাড়া বাংলাদেশের সাম্প্রতিক যে কোন ডাটা বা তথ্য এই বইতে পাবেন ...
তাই একজন নাগরিক হিসাবে এই তথ্য গুলো আপনার জানা প্রয়োজন ...।
বিসিএস ও ব্যাংক এর লিখিত পরীক্ষা ...+এছাড়া মাধ্যমিক ও উচ্চমাধ্যমিকের স্টুডেন্টদের জন্য অনেক কাজে আসবে ...
Communicating effectively and consistently with students can help them feel at ease during their learning experience and provide the instructor with a communication trail to track the course's progress. This workshop will take you through constructing an engaging course container to facilitate effective communication.
This document provides an overview of wound healing, its functions, stages, mechanisms, factors affecting it, and complications.
A wound is a break in the integrity of the skin or tissues, which may be associated with disruption of the structure and function.
Healing is the body’s response to injury in an attempt to restore normal structure and functions.
Healing can occur in two ways: Regeneration and Repair
There are 4 phases of wound healing: hemostasis, inflammation, proliferation, and remodeling. This document also describes the mechanism of wound healing. Factors that affect healing include infection, uncontrolled diabetes, poor nutrition, age, anemia, the presence of foreign bodies, etc.
Complications of wound healing like infection, hyperpigmentation of scar, contractures, and keloid formation.
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxEduSkills OECD
Iván Bornacelly, Policy Analyst at the OECD Centre for Skills, OECD, presents at the webinar 'Tackling job market gaps with a skills-first approach' on 12 June 2024
How to Make a Field Mandatory in Odoo 17Celine George
In Odoo, making a field required can be done through both Python code and XML views. When you set the required attribute to True in Python code, it makes the field required across all views where it's used. Conversely, when you set the required attribute in XML views, it makes the field required only in the context of that particular view.
Gender and Mental Health - Counselling and Family Therapy Applications and In...PsychoTech Services
A proprietary approach developed by bringing together the best of learning theories from Psychology, design principles from the world of visualization, and pedagogical methods from over a decade of training experience, that enables you to: Learn better, faster!
Leveraging Generative AI to Drive Nonprofit InnovationTechSoup
In this webinar, participants learned how to utilize Generative AI to streamline operations and elevate member engagement. Amazon Web Service experts provided a customer specific use cases and dived into low/no-code tools that are quick and easy to deploy through Amazon Web Service (AWS.)
Strategies for Effective Upskilling is a presentation by Chinwendu Peace in a Your Skill Boost Masterclass organisation by the Excellence Foundation for South Sudan on 08th and 09th June 2024 from 1 PM to 3 PM on each day.
Temple of Asclepius in Thrace. Excavation resultsKrassimira Luka
The temple and the sanctuary around were dedicated to Asklepios Zmidrenus. This name has been known since 1875 when an inscription dedicated to him was discovered in Rome. The inscription is dated in 227 AD and was left by soldiers originating from the city of Philippopolis (modern Plovdiv).
2. A script is a small piece of program that can add interactivity to
your website.
For example, a script could generate a pop-up alert box message,
or provide a dropdown menu.
This script could be written using Javascript orVBScript.
You can write various small functions, called event handlers
using any of the scripting language and then you can trigger those
functions using HTML attributes.
Now a days only Javascript and associated frameworks are being
used by most of the web developers, VBScript is not even
supported by various major browsers.
You can keep Javascript code in a separate file and then include it
whereever it's needed,
or you can define functionality inside HTML document itself. Let's
see both the cases one by one with suitable examples.
3. The <script> tag is used to define a client-side script (JavaScript).
The <script> element either contains scripting statements, or it
points to an external script file through the src attribute.
Common uses for JavaScript are image manipulation, form
validation, and dynamic changes of content.
To select an HTML element, JavaScript very often use the
document.getElementById(id) method.
This JavaScript example writes "Hello JavaScript!" into an HTML
element with id="demo"
5. Client Side
Scripts that execute in client side. In context of
websites, it is scripts that execute in the browser of
the user.
Eg: Javascript,VB etc.
Server Side
Scripts that execute in the Server. In context of
website, it is scripts that execute on application
servers.
Eg: PHP, Python, Ruby etc
6. Client-Side JavaScript (CSJS)
It is JavaScript that enables the enables web
pages on browsers to run active online content.
Server-Side JavaScript (SSJS)
It is JavaScript that enables back-end access to
databases, file systems, and servers.
7. You can write your script code directly into
your HTML document.
Usually we keep script code in header
of the document using <script> tag,
otherwise there is no restriction and you
can put your source code anywhere in the
document but inside <script> tag.
9. If you are going to define a functionality
which will be used in various HTML
documents then it's better to keep that
functionality in a separate Javascript file
and then include that file in your HTML
documents.
A Javascript file will have extension as .js and
it will be included in HTML files using <script>
tag.
10. Consider we define a small function using
Javascript in script.js which has following
code:
function Hello()
{
alert("Hello,World");
}
11. Now let's make use of the above external Javascript file in
our following HTML document:
<!DOCTYPE html>
<html>
<head>
<title>Javascript External Script</title>
<script src="/html/script.js" type="text/javascript"/></script>
</head>
<body>
<input type="button" onclick="Hello();" name="ok"
value="Click Me" />
</body> </html>
12. In JavaScript, almost "everything" is an object.
Booleans can be objects (if defined with the new keyword)
Numbers can be objects (if defined with the new keyword)
Strings can be objects (if defined with the new keyword)
Dates are always objects
Maths are always objects
Regular expressions are always objects
Arrays are always objects
Functions are always objects
Objects are always objects
All JavaScript values, except primitives, are objects.
13. A primitive value is a value that has no properties or methods.
A primitive data type is data that has a primitive value.
JavaScript defines 5 types of primitive data types:
string
number
boolean
null
undefined
Primitive values are immutable (they are hardcoded and therefore cannot be
changed).
if x = 3.14, you can change the value of x. But you cannot change the value of
3.14.
15. Arithmetic operators are used to perform
arithmetic on numbers:
Operator Description
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
++ Increment
-- Decrement
Arithmetic operators are
used to perform arithmetic
on numbers:
var x = 5;
var y = 2;
var z = x * y;
16. <!DOCTYPE html>
<html>
<body>
<p>A typical arithmetic operation takes two numbers (or expressions) and
produces a new number.</p>
<p id="demo"></p>
<script>
var a = 3;
var x = (100 + 50) * a;
document.getElementById("demo").innerHTML = x;
</script>
</body>
</html>
17. The basic assignment
operator is equal ( = ),
which assigns the value of
its right operand to its left
operand.That is, x = y
assigns the value of y to x
.
var x = 10;
x += 5;
var x = 10;
x -= 5;
var x = 10;
x *= 5;
var x = 10;
x /= 5;
Operator Example Same As
= x = y x = y
+= x += y x = x + y
-= x -= y x = x - y
*= x *= y x = x * y
/= x /= y x = x / y
%= x %= y x = x % y
<<= x <<= y x = x << y
>>= x >>= y x = x >> y
>>>= x >>>= y x = x >>> y
&= x &= y x = x & y
^= x ^= y x = x ^ y
|= x |= y x = x | y
**= x **= y x = x ** y
18. <!DOCTYPE html>
<html>
<body>
<h1>The /= Operator</h1>
<p id="demo"></p>
<script>
var x = 10;
x /= 5;
document.getElementById("demo").innerHTML = x;
</script>
</body>
</html>
19. JavaScript strings are used for storing and
manipulating text.
A JavaScript string simply stores a series of
characters like "John Doe".
A string can be any text inside quotes.You
can use single or double quotes.
var answer = "It's alright";
var answer = "He is called 'Johnny'";
var answer = 'He is called "Johnny"';
20. <!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var answer1 = "It's alright";
var answer2 = "He is called 'Johnny'";
var answer3 = 'He is called "Johnny"';
document.getElementById("demo").innerHTML =
answer1 + answer2 + answer3;
</script>
</body>
</html>
22. Finding a String in a String
The indexOf() method returns the index of (the position of) the first occurrence of a specified text in
a string:
<!DOCTYPE html>
<html>
<body>
<p id="p1">Please locate where 'locate' occurs!.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var str = document.getElementById("p1").innerHTML;
var pos = str.indexOf("locate");
document.getElementById("demo").innerHTML = pos;
}
</script>
</body>
</html>
23. Searching for a String in a String
The search() method searches a string for a specified value and returns the position of the match:
<!DOCTYPE html>
<html>
<body>
<p id="p1">Please locate where 'locate' occurs!.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var str = document.getElementById("p1").innerHTML;
var pos = str.search("locate");
document.getElementById("demo").innerHTML = pos;
}
</script>
</body>
</html>
24. Extracting String Parts
There are 3 methods for extracting a part of a string:
▪ slice(start, end)
▪ substring(start, end)
▪ substr(start, length)
<!DOCTYPE html>
<html>
<body>
<p>The slice() method extract a part of a string
and returns the extracted parts in a new string:</p>
<p id="demo"></p>
<script>
var str = "Apple, Banana, Kiwi";
document.getElementById("demo").innerHTML = str.slice(7,13);
</script>
</body>
</html>
25. String Length
The lengthproperty returns the length of a string:
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
document.getElementById("demo").innerHTML = txt.length;
</script>
</body>
</html>
26. Comparison
and Logical
operators are
used to test
for true or
false.
Comparison
operators are
used in logical
statements to
determine
equality or
difference
between
variables or
values.
Given that x = 5, the table below explains the comparison operators:
27. <!DOCTYPE html>
<html>
<body>
<script>
var a=10;
var b=20;
var linebreak="<br />";
document.write("a==b:");
result=(a==b);
document.write(result);
document.write(linebreak);
document.write("a > b:");
result=(a>b);
document.write(result);
</script>
</body>
</html>
29. Conditional operator assigns a value to a
variable based on some condition.
Syntax
variablename = (condition) ? value1:value2
Example
var voteable = (age < 18) ? "Too young":"Old
enough";
30. <!DOCTYPE html>
<html>
<body>
<p>Input your age and click the button:</p>
<input id="age" value="18" />
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var age, voteable;
age = document.getElementById("age").value;
voteable = (age < 18) ? "Too young":"Old enough";
document.getElementById("demo").innerHTML = voteable + " to vote.";
}
</script>
</body>
</html>
31. If the operator appears before the variable, the
value is modified before the expression is
evaluated.
If the operator appears after the variable, the
value is modified after the expression is
evaluated.
In other words, given j = ++k;, the value of j is the
original value of k plus one;
given j = k++;, the value of j is the original value
of k, which is incremented after its value is
assigned to j.
32. <!DOCTYPE html>
<html>
<body>
<p>If the operator appears before the variable, the value is modified before the expression is evaluated. <br>
If the operator appears after the variable, the value is modified after the expression is evaluated.
</p>
<p id="Incrementbefore"></p>
<p id="Incrementafter"></p>
<script>
var j = 3;
var k = 10;
j=++k;
document.getElementById("Incrementbefore").innerHTML = j;
var j = 3;
var k = 10;
j=k++;
document.getElementById("Incrementafter").innerHTML = j;
</script>
</body>
</html>
33. As logical expressions are evaluated left to right,
they are tested for possible "short-circuit"
evaluation using the following rules:
false && (anything) is short-circuit evaluated to false.
true. || (anything) is short-circuit evaluated to true.
Short-circuit evaluation says, the second argument is
executed or evaluated only if the first argument does
not suffice to determine the value of the expression:
when the first argument of the AND (&&) function
evaluates to false, the overall value must be false;
and when the first argument of the OR (||) function
evaluates to true, the overall value must be true.
35. delete
The delete operator is used to delete an object, an
object's property or a specified element in an array,
returning true if the operation is possible, and false if not.
With the defined object 'fruit' below, the following delete
operations are possible:
fruit = new Object;
fruit.name = 'apple';
fruit.color = 'green';
fruit.size = 'large';
delete fruit.size;
36. new
The new operator can be used to create an instance of a user-defined
object type or of one of the built-in object types that has a
constructor function.
To create a user-defined object type you must first define it by writing
a function that specifies its name, properties and methods.
For example, the following function creates an object for books with
properties for title, category and author:
Code:
function book(title, category, author)
{
this.title = title
this.category = category
this.author = author
}
mybook = new book("TheThing", "horror", "John Lynch")
37. this
The keyword this is used to refer to the current object. In a method, it usually refers to the
calling object.
The keyword this is used as the parameter of the DescribeAge function to refer to whichever
object is calling it, as seen in the final bit of code which creates a specific instance of the Car
object whose Description property will now contain the string "Old-fashioned":
Code:
function describeAge(obj)
{
if(obj.year < 1996)
return "Old-fashioned"
else
return "Good-as-new"
}
function car(make, year, description)
{this.make = make, this.year = year, this.description = describeAge(this)}
myCar = new car("Ford", "1993", describeAge(this))
38. Void
The void operator evaluates an expression without
returning a value. Although the use of brackets after it
is optional, it is good style to use them.
The following example creates a hyperlink on the
word "green" which, when clicked, changes the
background color to light green:
Code:
<a
href="javascript:void(document.bgColor='lightgreen')">green</a>
39. When the break statement is used with a
switch statement, it breaks out of the switch
block.
This will stop the execution of more
execution of code and/or case testing inside
the block.
When the break statement is used in a loop,
it breaks the loop and continues executing
the code after the loop (if any).
40. <!DOCTYPE html>
<html>
<body>
<p>A loop with a break.</p>
<p id="demo"></p>
<script>
var text = "";
var i;
for (i = 0; i < 10; i++) {
if (i === 3) { break; }
text += "The number is " + i + "<br>";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
41. The continue statement breaks one iteration
(in the loop), if a specified condition occurs,
and continues with the next iteration in the
loop.
This example skips the value of 3:
Example
for (i = 0; i < 10; i++) {
if (i === 3) { continue; }
text += "The number is " + i + "<br>";
}
42. <!DOCTYPE html>
<html>
<body>
<p>A loop which will skip the step where i = 3.</p>
<p id="demo"></p>
<script>
var text = "";
var i;
for (i = 0; i < 10; i++) {
if (i === 3) { continue; }
text += "The number is " + i + "<br>";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
43. JavaScript comments can be used to explain
JavaScript code, and to make it more readable.
JavaScript comments can also be used to
prevent execution, when testing alternative
code.
Single line comments start with //.
Any text between // and the end of the line will
be ignored by JavaScript (will not be executed).
Multi-line comments start with /* and end
with */.
Any text between /* and */ will be ignored by
JavaScript.
44. <!DOCTYPE html>
<html>
<body>
<h1 id="myH"></h1>
<p id="myP"></p>
<script>
// Change heading:
document.getElementById("myH").innerHTML = "My First Page";
// Change paragraph:
document.getElementById("myP").innerHTML = "My first paragraph.";
</script>
<p><strong>Note:</strong>The comments are not executed.</p>
</body>
</html>
45. do...while Statement (JavaScript) Executes
a statement block once, and then repeats
execution of the loop until a condition
expression evaluates to false.
This loop will always be executed at least
once, even if the condition is false, because
the code block is executed before the
condition is tested
46. The while loop loops through a block of code as long as a
specified condition is true.
Syntax
while (condition) {
code block to be executed
}
Example
In the following example, the code in the loop will run, over and
over again, as long as a variable (i) is less than 10:
while (i < 10) {
text += "The number is " + i;
i++;
}
47. <!DOCTYPE html>
<html>
<body>
<h1>JavaScript while</h1>
<p id="demo"></p>
<script>
var text = "";
var i = 0;
while (i < 10) {
text += "<br>The number is " + i;
i++;
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
48. <!DOCTYPE html>
<html>
<body>
<p>Click the button to loop through a block of code as long as i is
less than 5.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var text = ""
var i = 0;
do {
text += "<br>The number is " + i;
i++;
}
while (i < 5);
document.getElementById("demo").innerHTML = text;
}
</script>
</body>
</html>
49. Loops can execute a block of code a number of times.
Loops are handy, if you want to run the same code over
and over again, each time with a different value.
Instead of writing:
text += cars[0] + "<br>";
text += cars[1] + "<br>";
text += cars[2] + "<br>";
text += cars[3] + "<br>";
text += cars[4] + "<br>";
text += cars[5] + "<br>";
You can write:
for (i = 0; i < cars.length; i++) {
text += cars[i] + "<br>";
}
50. <!DOCTYPE html>
<html>
<body>
<h1>JavaScript Loops</h1>
<p id="demo"></p>
<script>
var cars = ["BMW", "Volvo", "Saab", "Ford", "Fiat", "Audi"];
var text = "";
var i;
for (i = 0; i < cars.length; i++) {
text += cars[i] + "<br>";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
51. The for/in statement loops through the properties of an object.
The block of code inside the loop will be executed once for each
property.
JavaScript supports different kinds of loops:
for - loops through a block of code a number of times
for/in - loops through the properties of an object
Syntax
for (var in object) {
code block to be executed
}
52. <!DOCTYPE html>
<html>
<body>
<p>Click the button to loop through the properties of an object.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var person = {fname:"Arti", lname:"Gavas", city:"Airoli"};
var text = "";
var x;
for (x in person) {
text += person[x] + " ";
}
document.getElementById("demo").innerHTML = text;
}
</script>
</body>
</html>
53. Like the program itself, a function is composed of a
sequence of statements called the function body.
Values can be passed to a function, and the function
will return a value.
In JavaScript, functions are class objects, because
they can have properties and methods just like any
other object.
A JavaScript function is a block of code designed to
perform a particular task.
A JavaScript function is executed when "something"
invokes it (calls it).
54. <!DOCTYPE html>
<html>
<body>
<h1>JavaScript Functions</h1>
<p>This example calls a function which performs a calculation, and returns the
result:</p>
<p id="demo"></p>
<script>
function myFunction(p1, p2) {
return p1 * p2;
}
document.getElementById("demo").innerHTML = myFunction(4, 3);
</script>
</body>
</html>
55. Conditional statements are used to perform different
actions based on different conditions.
In JavaScript we have the following conditional
statements:
Use if to specify a block of code to be executed, if a
specified condition is true
Use else to specify a block of code to be executed, if the
same condition is false
Use else if to specify a new condition to test, if the first
condition is false
Use switch to specify many alternative blocks of code
to be executed
56. Use the if statement to specify a block of
JavaScript code to be executed if a condition
is true.
Syntax
if (condition) {
block of code to be executed if the condition
is true
}
57. <!DOCTYPE html>
<html>
<body>
<p>Display "Good day!" if the hour is less than 18:00:</p>
<p id="demo">Good Evening!</p>
<script>
if (new Date().getHours() < 18) {
document.getElementById("demo").innerHTML = "Good day!";
}
</script>
</body>
</html>
58. The switch statement evaluates an
expression.
The value of the expression is then compared
with the values of each case in the structure.
If there is a match, the associated block of
code is executed.
The switch statement is often used together
with a break or a default keyword (or both).
59. <!DOCTYPE html>
<html>
<body>
<p>Write Banana, Orange or Apple in the input field and click the
button.</p>
<p>The switch statement will execute a block of code based on
your input.</p>
<input id="myInput" type="text">
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var text;
var fruits =
document.getElementById("myInput").value;
switch(fruits) {
case "Banana":
text = "Banana is good!";
break;
case "Orange":
text = "I am not a fan of orange.";
break;
case "Apple":
text = "How you like them apples?";
break;
default:
text = "I have never heard of that
fruit...";
}
document.getElementById("demo").inner
HTML = text;
}
</script>
</body>
</html>
60. <!DOCTYPE html>
<html>
<body>
<p>Click the button to display what day it is today.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var day;
switch (new Date().getDay()) {
case 0:
day = "Sunday";
break;
case 1:
day = "Monday";
break;
case 2:
day = "Tuesday";
break;
case 3:
day = "Wednesday";
break;
case 4:
day = "Thursday";
break;
case 5:
day = "Friday";
break;
case 6:
day = "Saturday";
break;
default:
day = "Unknown Day";
}
document.getElementById("demo"
).innerHTML = "Today is " + day;
}
</script>
</body>
</html>
61. import.The import statement is used to
import functions, objects or primitives that
have been exported from an external module,
another script, etc.
Note:This feature is not implemented in any
browsers natively at this time.
It is implemented in many transpilers, such as
theTraceur Compiler, Babel, Rollup or
Webpack
62. Label statement provides an identifier for a
statement that lets you refer to it using a
break or continue statement.
Syntax
label :Statements
label : Any JavaScript identifier that is not a reserved word.
statements : Group of statements. "Break" can be used
with any labeled statement, and "continue" can be used with
looping labeled statements.
63. <!DOCTYPE html>
<html>
<body>
<h1>The Label Statement</h1>
<script>
labelmark:
for(x=0; x<6; x++)
{
var newParagraph1 = document.createElement("p");
if(x==3)
{
break labelmark; // see the output using continue statement
}
var newText1 = document.createTextNode("The value of x is : " +x);
newParagraph1.appendChild(newText1);
document.body.appendChild(newParagraph1);
}
var newParagraph1 = document.createElement("p");
var newText1 = document.createTextNode("The last value of x is : " +x);
newParagraph1.appendChild(newText1);
document.body.appendChild(newParagraph1);
</script>
</body>
</html>
64. The return statement stops the execution of
a function and returns a value from that
function.
Example
Return the value of PI:
function myFunction() {
return Math.PI;
}
The result will be:
▪ 3.141592653589793
65. <!DOCTYPE html>
<html>
<body>
<p>This example calls a function which returns the value of PI:</p>
<p id="demo"></p>
<script>
function myFunction() {
return Math.PI;
}
document.getElementById("demo").innerHTML = myFunction();
</script>
</body>
</html>