This document provides an overview of type conversion and regular expressions in JavaScript. It discusses how JavaScript variables can be converted between different data types either automatically or using functions. It covers converting between numbers, strings, booleans, and dates. It also provides an introduction to regular expressions including patterns, modifiers, and examples of using regular expression methods like exec(), test(), search(), split(), and replace() on strings. The document includes exercises for readers to practice these concepts.
Generally speaking, a function is a "subprogram" that can be called by code external (or internal in the case of recursion) to the function. 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 first-class objects, because they can have properties and methods just like any other object. What distinguishes them from other objects is that functions can be called. In brief, they are Function objects.
JavaScript - Chapter 4 - Types and StatementsWebStackAcademy
A computer program is a list of "instructions" to be "executed" by a computer.
In a programming language, these programming instructions are called statements.
A JavaScript program is a list of programming statements.
JavaScript statements are composed of:
Values, Operators, Expressions, Keywords, and Comments.
This statement tells the browser to write "Hello Dolly." inside an HTML element with id="demo":
JavaScript Data Types
JavaScript variables can hold many data types: numbers, strings, objects and more.
In programming, data types is an important concept.
To be able to operate on variables, it is important to know something about the type.
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
JavaScript String:
The String object lets you work with a series of characters; it wraps Javascript's string primitive data type with a number of helper methods.
As JavaScript automatically converts between string primitives and String objects, you can call any of the helper methods of the String object on a string primitive.
JavaScript Arrays:
The Array object lets you store multiple values in a single variable. It stores a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.
A JavaScript function is a block of code designed to perform a particular task.
Why Functions?
You can reuse code: Define the code once, and use it many times. You can use the same code many times with different arguments, to produce different results.
JavaScript - An Introduction is a beginner's guide to JavaScript. It starts with very basic level and goes to intermediate level. You'll be introduced with every language constructs, Event handling, Form handling and AJAX which is supported by JavaScript with XMLHttpRequest object. This XHR object is discussed in enough detail so that you can understand how the underlying AJAX functionality works in jQuery. At the end it discusses advance concepts and library build on/around JavaScript.
Generally speaking, a function is a "subprogram" that can be called by code external (or internal in the case of recursion) to the function. 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 first-class objects, because they can have properties and methods just like any other object. What distinguishes them from other objects is that functions can be called. In brief, they are Function objects.
JavaScript - Chapter 4 - Types and StatementsWebStackAcademy
A computer program is a list of "instructions" to be "executed" by a computer.
In a programming language, these programming instructions are called statements.
A JavaScript program is a list of programming statements.
JavaScript statements are composed of:
Values, Operators, Expressions, Keywords, and Comments.
This statement tells the browser to write "Hello Dolly." inside an HTML element with id="demo":
JavaScript Data Types
JavaScript variables can hold many data types: numbers, strings, objects and more.
In programming, data types is an important concept.
To be able to operate on variables, it is important to know something about the type.
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
JavaScript String:
The String object lets you work with a series of characters; it wraps Javascript's string primitive data type with a number of helper methods.
As JavaScript automatically converts between string primitives and String objects, you can call any of the helper methods of the String object on a string primitive.
JavaScript Arrays:
The Array object lets you store multiple values in a single variable. It stores a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.
A JavaScript function is a block of code designed to perform a particular task.
Why Functions?
You can reuse code: Define the code once, and use it many times. You can use the same code many times with different arguments, to produce different results.
JavaScript - An Introduction is a beginner's guide to JavaScript. It starts with very basic level and goes to intermediate level. You'll be introduced with every language constructs, Event handling, Form handling and AJAX which is supported by JavaScript with XMLHttpRequest object. This XHR object is discussed in enough detail so that you can understand how the underlying AJAX functionality works in jQuery. At the end it discusses advance concepts and library build on/around JavaScript.
What is JavaScript?
JavaScript is a very powerful client-side scripting language. JavaScript is used mainly for enhancing the interaction of a user with the webpage. In other words, you can make your webpage more lively and interactive, with the help of JavaScript. JavaScript is also being used widely in game development and Mobile application development.
Debugging in JavaScript
It is common to have errors while writing codes and the errors can be due to syntax or logical. These errors create a lot of ambiguity in the logic and understanding of both users and programmers. There can also be errors in the code which can remain invisible to the programmer’s eye and can create havoc. To identify these errors we need Debuggers that can go through the entire code or program, identify the errors and also fix them.
-Debugger
The debugger keyword is used in the code to force stop the execution of the code at a breaking point and calls the debugging function. The debugger function is executed if any debugging is needed at all else no action is performed.
JavaScript Arithmetic Operators
Arithmetic operators are used to perform arithmetic between variables and/or values.
JavaScript Assignment Operators
Assignment operators are used to assign values to JavaScript variables.
JavaScript String Operators
The + operator, and the += operator can also be used to concatenate (add) strings.
Comparison Operators
Comparison operators are used in logical statements to determine equality or difference between variables or values.
Conditional (Ternary) Operator
The conditional operator assigns a value to a variable based on a condition.
Logical Operators
Logical operators are used to determine the logic between variables or values.
JavaScript Bitwise Operators
Bit operators work on 32 bits numbers. Any numeric operand in the operation is converted into a 32 bit number. The result is converted back to a JavaScript number.
The delete Operator
The delete operator deletes a property from an object:
Java 8 Stream API. A different way to process collections.David Gómez García
A look on one of the features of Java 8 hidden behind the lambdas. A different way to iterate Collections. You'll never see the Collecions the same way.
These are the slides I used on my talk at the "Tech Thursday" by Oracle in June in Madrid.
JavaScript Events:
HTML events are "things" that happen to HTML elements. When JavaScript is used in HTML pages, JavaScript can "react" on these events.
What can JavaScript Do?
Event handlers can be used to handle, and verify, user input, user actions, and browser actions:
Things that should be done every time a page loads
Things that should be done when the page is closed
Action that should be performed when a user clicks a button
Content that should be verified when a user inputs data
What is JavaScript?
JavaScript is a very powerful client-side scripting language. JavaScript is used mainly for enhancing the interaction of a user with the webpage. In other words, you can make your webpage more lively and interactive, with the help of JavaScript. JavaScript is also being used widely in game development and Mobile application development.
Debugging in JavaScript
It is common to have errors while writing codes and the errors can be due to syntax or logical. These errors create a lot of ambiguity in the logic and understanding of both users and programmers. There can also be errors in the code which can remain invisible to the programmer’s eye and can create havoc. To identify these errors we need Debuggers that can go through the entire code or program, identify the errors and also fix them.
-Debugger
The debugger keyword is used in the code to force stop the execution of the code at a breaking point and calls the debugging function. The debugger function is executed if any debugging is needed at all else no action is performed.
JavaScript Arithmetic Operators
Arithmetic operators are used to perform arithmetic between variables and/or values.
JavaScript Assignment Operators
Assignment operators are used to assign values to JavaScript variables.
JavaScript String Operators
The + operator, and the += operator can also be used to concatenate (add) strings.
Comparison Operators
Comparison operators are used in logical statements to determine equality or difference between variables or values.
Conditional (Ternary) Operator
The conditional operator assigns a value to a variable based on a condition.
Logical Operators
Logical operators are used to determine the logic between variables or values.
JavaScript Bitwise Operators
Bit operators work on 32 bits numbers. Any numeric operand in the operation is converted into a 32 bit number. The result is converted back to a JavaScript number.
The delete Operator
The delete operator deletes a property from an object:
Java 8 Stream API. A different way to process collections.David Gómez García
A look on one of the features of Java 8 hidden behind the lambdas. A different way to iterate Collections. You'll never see the Collecions the same way.
These are the slides I used on my talk at the "Tech Thursday" by Oracle in June in Madrid.
JavaScript Events:
HTML events are "things" that happen to HTML elements. When JavaScript is used in HTML pages, JavaScript can "react" on these events.
What can JavaScript Do?
Event handlers can be used to handle, and verify, user input, user actions, and browser actions:
Things that should be done every time a page loads
Things that should be done when the page is closed
Action that should be performed when a user clicks a button
Content that should be verified when a user inputs data
What is JavaScript Regex | Regular Expressions in JavaScript | EdurekaEdureka!
YouTube Link: https://youtu.be/B5iF6XBpcsI
** Full Stack Web Developer Masters Program: https://www.edureka.co/masters-program/full-stack-developer-training **
This Edureka PPT on "JavaScript Regex" will help you understand regular expression in JavaScript and how they are used to perform pattern matching in any string.
Follow us to never miss an update in the future.
YouTube: https://www.youtube.com/user/edurekaIN
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
Castbox: https://castbox.fm/networks/505?country=in
Regular Expressions: JavaScript And BeyondMax Shirshin
Regular Expressions is a powerful tool for text and data processing. What kind of support do browsers provide for that? What are those little misconceptions that prevent people from using RE effectively?
The talk gives an overview of the regular expression syntax and typical usage examples.
It is a mechanism that enables us to sew/embed/bind WORDS in between a processed/unprocessed string literal.
Here by the processed string literal we mean processing of meta-characters like escape sequences(\n, \t, \r etc.) in the string.
Webstack Academy - Course Demo Webinar and Placement JourneyWebStackAcademy
At WebStack Academy, we understand the importance of providing valuable insights to aspiring professionals like yourself. That's why we host monthly webinars tailored to address the needs of ambitious individuals. Led by our esteemed experts - Mr. Jayakumar (Director, WebStack Academy) and Mr. Mubeen (Technology Head, WebStack Academy), the presentation will offer a firsthand understanding of industry trends, career pathways, and how our Full Stack course can be the catalyst to realizing your career aspirations.
WSA: Scaling Web Service to Handle Millions of Requests per SecondWebStackAcademy
In this presentation of Venkata Ramana Gollamudi, Principal Architect at Flipkart, as our esteemed speaker. With his expertise and experience, he'll guide us through the intricate process of “Scaling web service to handle millions of requests per second”.
Key Takeaways:
Understanding the specific challenges of scaling for Indian users
Strategies to ensure service availability, reduce latency, and maintain reliability
Leveraging tools like ELBs, K8s, message queues, and NoSQL databases effectively
Don't miss this unparalleled opportunity to gain invaluable insights and elevate your expertise in scaling web services to new heights.
We eagerly await your participation in this transformative webinar. Let's embark on the journey to mastering scalability together!
WSA: Course Demo Webinar - Full Stack Developer CourseWebStackAcademy
At WebStack Academy, we understand the importance of providing valuable insights to aspiring professionals like yourself. We host monthly webinars tailored to address the needs of ambitious individuals. Led by our esteemed experts - Mr. Jayakumar (Director, WebStack Academy) and Mr. Mubeen (Technology Head, WebStack Academy), these webinars presentation deck offer a firsthand understanding of industry trends, career pathways, and how our Full Stack course can be the catalyst to realizing your career aspirations.
Career Building in AI - Technologies, Trends and OpportunitiesWebStackAcademy
We from WSA always believe in sharing the right information and enabling you to make decisions for your long term career.
In this regard, Masterclass Webinar on "Career Building in AI - Technologies, Trends and Opportunities” by Renganathan Sekar - Product Manager, Artificial Intelligence - Samsung Research Institute.
Key takeaways from this slide deck:
*Gain a comprehensive overview of AI and its wide range of applications.
*Explore real-world use cases that exemplify the incredible potential of AI.
*Delve into the core technologies driving AI innovation.
*Stay ahead of recent trends in AI, including the intriguing concept of Gen AI.
*Uncover a wealth of opportunities in the AI landscape.
*Learn effective strategies to up skill and advance your career in the AI industry.
WSA Free online Internship for Web Development is an Online real-time experience for Engineering students. It will take you through a journey of skill building and project building experience. You will understand the various product development phases and skills required to work on any Web Application product in Industry.
A guide designed to help you master the art of web development. The roadmap provides a comprehensive step-by-step guide to learn foundational web technologies like HTML, CSS, & JavaScript, advanced frameworks, and concepts required for modern web development. It aims to equip aspiring developers with the necessary resources and tools to excel in the ever-evolving world of web development. 💡
Angular - Chapter 9 - Authentication and AuthorizationWebStackAcademy
Authentication is the process of validating a user on the credentials (username and password)
and provide access to the web application(ex: Email)
Authorization helps you to control access rights by granting or denying specific permissions
to an authenticated user (Ex: User / Manager / Admin).
Http Service will help us fetch external data, post to it, etc. We need to import the http module to make use of the http service. Let us consider an example to understand how to make use of the http service.
AngularFire is the officially supported AngularJS binding for Firebase. ... The focus of this library is to abstract much of the boilerplate involved in creating Angular bindings from Firebase to Angular, and to make it easy to create services that sync to your database.
A directive is a custom HTML element that is used to extend the power of HTML. Angular 2 has the following directives that get called as part of the BrowserModule module.
ngif
ngFor
If you view the app.module.ts file, you will see the following code and the BrowserModule module defined. By defining this module, you will have access to the 2 directives.
Angular - Chapter 4 - Data and Event HandlingWebStackAcademy
In Angular , events such as button click or any other sort of events can also be handled very easily. The events get triggered from the html page and are sent across to Angular JS class for further processing.
Data binding is a core concept in Angular and allows to define communication between a component and the DOM, making it very easy to define interactive applications without worrying about pushing and pulling data. There are four forms of data binding and they differ in the way the data is flowing.
Components are the most basic UI building block of an Angular app. An Angular app contains a tree of Angular components.
Angular components are a subset of directives, always associated with a template. Unlike other directives, only one component can be instantiated per an element in a template.
A component must belong to an NgModule in order for it to be available to another component or application. To make it a member of an NgModule, list it in the declarations field of the NgModule metadata.
TypeScript lets you write JavaScript the way you really want to. TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. TypeScript is pure object oriented with classes, interfaces and statically typed like C# or Java. The popular JavaScript framework Angular 2.0 is written in TypeScript. Mastering TypeScript can help programmers to write object-oriented programs and have them compiled to JavaScript, both on server side and client side.
AngularJS is a structural framework for dynamic web apps. It lets you use HTML as your template language and lets you extend HTML's syntax to express your application's components clearly and succinctly. AngularJS's data binding and dependency injection eliminate much of the code you would otherwise have to write. And it all happens within the browser, making it an ideal partner with any server technology.
Form validation normally used to occur at the server, after the client had entered all the necessary data and then pressed the Submit button. If the data entered by a client was incorrect or was simply missing, the server would have to send all the data back to the client and request that the form be resubmitted with correct information. This was really a lengthy process which used to put a lot of burden on the server.
JavaScript provides a way to validate form's data on the client's computer before sending it to the web server. Form validation generally performs two functions.
Basic Validation − First of all, the form must be checked to make sure all the mandatory fields are filled in. It would require just a loop through each field in the form and check for data.
Data Format Validation − Secondly, the data that is entered must be checked for correct form and value. Your code must include appropriate logic to test correctness of data.
The Browser Object Model (BOM) in JavaScript includes the properties and methods for JavaScript to interact with the web browser.
BOM provides you with window object, for example, to show the width and height of the window. It also includes the window.screen object to show the width and height of the screen.
What is the DOM?
The DOM is a W3C (World Wide Web Consortium) standard.
The DOM defines a standard for accessing documents:
"The W3C Document Object Model (DOM) is a platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document."
The W3C DOM standard is separated into 3 different parts:
Core DOM - standard model for all document types
XML DOM - standard model for XML documents
HTML DOM - standard model for HTML documents
The HTML DOM (Document Object Model)
When a web page is loaded, the browser creates a Document Object Model of the page.
The HTML DOM model is constructed as a tree of Objects.
With the HTML DOM, JavaScript can access and change all the elements of an HTML document.
JavaScript (JS) is a lightweight interpreted or just-in-time compiled programming language with first-class functions. While it is most well-known as the scripting language for Web pages, many non-browser environments also use it, such as Node.js, Apache CouchDB and Adobe Acrobat. JavaScript is a prototype-based, multi-paradigm, dynamic language, supporting object-oriented, imperative, and declarative (e.g. functional programming) styles.
JQuery provides methods to manipulate DOM in efficient way. You do not need to write big code to modify the value of any element's attribute or to extract HTML code from a paragraph or division.
JQuery provides methods such as .attr(), .html(), and .val() which act as getters, retrieving information from DOM elements for later use.
Let's dive deeper into the world of ODC! Ricardo Alves (OutSystems) will join us to tell all about the new Data Fabric. After that, Sezen de Bruijn (OutSystems) will get into the details on how to best design a sturdy architecture within ODC.
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
💥 Speed, accuracy, and scaling – discover the superpowers of GenAI in action with UiPath Document Understanding and Communications Mining™:
See how to accelerate model training and optimize model performance with active learning
Learn about the latest enhancements to out-of-the-box document processing – with little to no training required
Get an exclusive demo of the new family of UiPath LLMs – GenAI models specialized for processing different types of documents and messages
This is a hands-on session specifically designed for automation developers and AI enthusiasts seeking to enhance their knowledge in leveraging the latest intelligent document processing capabilities offered by UiPath.
Speakers:
👨🏫 Andras Palfi, Senior Product Manager, UiPath
👩🏫 Lenka Dulovicova, Product Program Manager, UiPath
UiPath Test Automation using UiPath Test Suite series, part 4DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 4. In this session, we will cover Test Manager overview along with SAP heatmap.
The UiPath Test Manager overview with SAP heatmap webinar offers a concise yet comprehensive exploration of the role of a Test Manager within SAP environments, coupled with the utilization of heatmaps for effective testing strategies.
Participants will gain insights into the responsibilities, challenges, and best practices associated with test management in SAP projects. Additionally, the webinar delves into the significance of heatmaps as a visual aid for identifying testing priorities, areas of risk, and resource allocation within SAP landscapes. Through this session, attendees can expect to enhance their understanding of test management principles while learning practical approaches to optimize testing processes in SAP environments using heatmap visualization techniques
What will you get from this session?
1. Insights into SAP testing best practices
2. Heatmap utilization for testing
3. Optimization of testing processes
4. Demo
Topics covered:
Execution from the test manager
Orchestrator execution result
Defect reporting
SAP heatmap example with demo
Speaker:
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
"Impact of front-end architecture on development cost", Viktor TurskyiFwdays
I have heard many times that architecture is not important for the front-end. Also, many times I have seen how developers implement features on the front-end just following the standard rules for a framework and think that this is enough to successfully launch the project, and then the project fails. How to prevent this and what approach to choose? I have launched dozens of complex projects and during the talk we will analyze which approaches have worked for me and which have not.
PHP Frameworks: I want to break free (IPC Berlin 2024)Ralf Eggert
In this presentation, we examine the challenges and limitations of relying too heavily on PHP frameworks in web development. We discuss the history of PHP and its frameworks to understand how this dependence has evolved. The focus will be on providing concrete tips and strategies to reduce reliance on these frameworks, based on real-world examples and practical considerations. The goal is to equip developers with the skills and knowledge to create more flexible and future-proof web applications. We'll explore the importance of maintaining autonomy in a rapidly changing tech landscape and how to make informed decisions in PHP development.
This talk is aimed at encouraging a more independent approach to using PHP frameworks, moving towards a more flexible and future-proof approach to PHP development.
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
GraphRAG is All You need? LLM & Knowledge GraphGuy Korland
Guy Korland, CEO and Co-founder of FalkorDB, will review two articles on the integration of language models with knowledge graphs.
1. Unifying Large Language Models and Knowledge Graphs: A Roadmap.
https://arxiv.org/abs/2306.08302
2. Microsoft Research's GraphRAG paper and a review paper on various uses of knowledge graphs:
https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
Sidekick Solutions uses Bonterra Impact Management (fka Social Solutions Apricot) and automation solutions to integrate data for business workflows.
We believe integration and automation are essential to user experience and the promise of efficient work through technology. Automation is the critical ingredient to realizing that full vision. We develop integration products and services for Bonterra Case Management software to support the deployment of automations for a variety of use cases.
This video focuses on the notifications, alerts, and approval requests using Slack for Bonterra Impact Management. The solutions covered in this webinar can also be deployed for Microsoft Teams.
Interested in deploying notification automations for Bonterra Impact Management? Contact us at sales@sidekicksolutionsllc.com to discuss next steps.
JMeter webinar - integration with InfluxDB and GrafanaRTTS
Watch this recorded webinar about real-time monitoring of application performance. See how to integrate Apache JMeter, the open-source leader in performance testing, with InfluxDB, the open-source time-series database, and Grafana, the open-source analytics and visualization application.
In this webinar, we will review the benefits of leveraging InfluxDB and Grafana when executing load tests and demonstrate how these tools are used to visualize performance metrics.
Length: 30 minutes
Session Overview
-------------------------------------------
During this webinar, we will cover the following topics while demonstrating the integrations of JMeter, InfluxDB and Grafana:
- What out-of-the-box solutions are available for real-time monitoring JMeter tests?
- What are the benefits of integrating InfluxDB and Grafana into the load testing stack?
- Which features are provided by Grafana?
- Demonstration of InfluxDB and Grafana using a practice web application
To view the webinar recording, go to:
https://www.rttsweb.com/jmeter-integration-webinar
5. www.webstackacademy.com
Converting Number to String
The String() and toString() can convert number to strings
String(234); //234
var n=45;
var x=n.toString(); // Result x is 45
8. www.webstackacademy.com
Converting String to Numbers
Option Description
Number() Convert Strings to numbers
parseFloat() Parses a string and returns a floating point number
parseInt() Parses a string and returns an Integer
9. www.webstackacademy.com
Unary +Operator
The unary + operator can be used to convert a variable to a number.
<body>
<button onclick="checkType()">Click this button</button>
<p id="ex"></p>
<script>
function checkType() {
var y = "5";
var x = + y;
document.getElementById("ex").innerHTML = typeof y + "<br>" + typeof x;
}
</script>
11. www.webstackacademy.com
Exercise
Revisit the rectangle program (area & perimeter). Check the output
with and without converting the input values.
Write a JavaScript program to convert current date into string.
13. www.webstackacademy.com
Regular Expression
Regular expressions are used for defining String patterns that can be used
for searching, manipulating and editing a text.
A regular expression, regex or regexp, in theoretical computer science.
The process of searching text to identify matches—strings that match a
regex's pattern—is pattern matching.
In JavaScript, regular expressions are also objects.
Regular expressions can be used to perform text search and text replace
operations.
14. www.webstackacademy.com
Regular Expression
Pattern:
Pattern specifications consist of a series of characters
These characters have a special meaning
They are also known as meta characters
Syntax:
var match = new RegExp(pattern, modifiers) (or)
var match = /pattern/modifiers
15. www.webstackacademy.com
Regular Expression
Modifiers are a series of characters indicating various options
They are optional in a regular expression
This syntax is borrowed from Perl, supports some of them
Perl was originally designed for pattern matching
Option Description
g Global matching. When using the replace() method, specify this modifier to replace
all matches, rather than only the first one.
i Case insensitive matching
m Multi-line mode. In this mode, the caret and dollar match before and after newlines
in the subject string
17. www.webstackacademy.com
Regular Expression patterns
Character Meaning
Indicates that the next character is special and not to be interpreted
literally
^ Matches the beginning of the string or line.
$ Matches the end of the string or line.
* Matches the previous character 0 or more times.
+ Matches the previous character 1 or more times.
n Matches a New line
? Matches the previous character 0 or 1 time.
. Find a single character, except newline or line terminator
18. www.webstackacademy.com
Regular Expression Pattern
Brackets are used to find range of characters.
Expression Description
[abc] Find any of the characters between the bracket
[^abc] Find any character NOT between the brackets
[0-9] Find any of the digits between the brackets
[^0-9] Find any character NOT between the brackets (any non-digit)
(x|y) Find any of the alternatives separated with |
19. www.webstackacademy.com
Regular Expression Example
<script>
function upper_case(str)
{
var regexp = /^[A-Z]/;
if (regexp.test(str))
{
console.log("String's first character is uppercase");
}
else
{
console.log("String's first character is not uppercase");
}
}
upper_case('Webstack Academy');
upper_case('webstack academy');
</script>
20. www.webstackacademy.com
Metacharacters
Meta character Description
d Find a digit
D Find a non digit character
w Find a word character
W Find a non word character
s Find a whitespace character
S Find a non-whitespace character
b Find a match at the beginning or end of the word
B Find a match not at the beginning or end of the word
0 Find a Null character
uxxxx Find a uni-code character specified by the hexadecimal number xxxx
21. www.webstackacademy.com
Examples
var pattern =/^abc/;
var pattern = /xy{3,5}z/;
var pattern =/[a-z]/;
var pattern = /abc.d/;
Matches only those string beginning with abc.
Matches a single “x” followed by y characters between three and five and then the
letter z
Matches any lowercase alphabetic character
Matches any character except a newline
22. www.webstackacademy.com
Exercise
WAP that will match any string containing “world”.
WAP to check whether the given string is alphanumeric or not
WAP to validate the mobile number in a given format (+91 98412 32534)
WAP to validate credit card in a given format (4312-8763-9823-1234)
WAP to validate a discount code (PIZDIS400)
Invalid format
Invalid coupon code
24. www.webstackacademy.com
The Exec() Method
The exec() method of the RegExp object is used to execute the search for a
match in a specified string.
Example:
/c/.exec("In JavaScript, regular expressions are also objects.");
Syntax:
Regexp.exec(str);
25. www.webstackacademy.com
The test() Method
The test() method of the RegExp executes a search for a match between a
regular expression and a specified string.
It will return true or false.
Syntax:
Regexp.test(str);
26. www.webstackacademy.com
Example
<script>
regExpr = new RegExp('like','g')
// Define a string.
str1 = 'Happiness radiates like the fragrance from a flower';
// Check whether regular expression exists in the string.
if (regExpr.test(str1))
{
document.write("'like' is found in " + str1);
}
</script>
28. www.webstackacademy.com
String Methods for Regular Expressions
It will return the index of character at which the first matching substrings begins.
<script>
var str = "I like apple";
var n = str.search(/Apple/i);
document.write(n);
</script>
Output : 7
Syntax:
str.search(pattern);
29. www.webstackacademy.com
The split()
• The split() method splits a string into sub strings and return them in an array
• Separator is used to split the string
• Limit specifies the number of splits
Syntax:
str.split(separator,limit);
<script>
var str = “10/3/5/6/5";
var split = str.split(/[/]+/);
document.write(split);
</script>
30. www.webstackacademy.com
The replace()
var str = "Hello.How are You?";
// Replace first dot with exclamation mark (!)
var res = str.replace(/./, "!");
alert(res);
Syntax:
str.search(searchvalue,newvalue);
• The search() method searches for the given String / RegExp, replaces new value
• In case of RegExp the first match is replaced. For all replacements use ‘g’ modifier