SlideShare a Scribd company logo
JavaScript Built-in objects 
JavaScript supports a number of built-in objects that extend the flexibility of the language. These objects 
are Date, Math, String, Array, and Object. 
1. String Objects : 
<html> 
<body> 
<p id="demo"></p> 
<script> 
var carName1 = "Volvo XC60"; 
var carName2 = 'Volvo XC60'; 
var answer1 = "It's alright"; 
var answer2 = "He is called 'Johnny'"; 
var answer3 = 'He is called "Johnny"'; 
document.getElementById("demo").innerHTML = 
carName1 + "<br>" + 
carName2 + "<br>" + 
answer1 + "<br>" + 
answer2 + "<br>" + 
answer3; 
</script></body></html> 
2. String Length: 
<html><body> 
<p id="demo"></p> 
<script> 
var txt="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
document.getElementById("demo").innerHTML = txt.length; 
</script></body></html> 
3. Strings can be Objects 
 Normally, JavaScript strings are primitive values, created from literals: var firstName = 
"John" 
 But strings can also be defined as objects with the keyword new: var firstName = new 
String("John") 
<html><body>
<p id="demo"></p> 
<script> 
var x = "John"; // x is a string 
var y = new String("John"); // y is an object 
document.getElementById("demo").innerHTML = typeof x + " " + typeof y; 
</script> 
</body></html> 
JavaScript string methods 
4. The slice() Method 
 Slice() extracts a part of a string and returns the extracted part in a new string. 
 The method takes 2 parameters: the starting index (position), and the ending index 
(position). 
 This example slices out a portion of a string from position 7 to position 13: 
<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> 
If a parameter is negative, the position is counted from the end of the string. 
5. This example slices out a portion of a string from position -12 to position -6: 
<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(-12,-6); 
</script></body></html>
6.If you omit the second parameter, the method will slice out the rest of the sting: 
<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); 
</script> 
</body></html> 
7. or, counting from the end : 
<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(-12); 
</script></body></html> 
8. The substring() Method 
 Substring () is similar to slice (). 
 The difference is that substring () cannot accept negative indexes. 
<html><body> 
<p>The substr() 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.substring(7,13); 
</script></body></html>
9. The substr() Method 
 substr() is similar to slice(). 
 The difference is that the second parameter specifies the length of the extracted part. 
<html><body> 
<p>The substr() 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.substr(7,6); 
</script></body></html> 
 If the first parameter is negative, the position counts from the end of the string. 
 The second parameter can not be negative, because it defines the length. 
 If you omit the second parameter, substr() will slice out the rest of the string. 
10. Replacing String Content 
 The replace() method replaces a specified value with another value in a string: 
<html><body> 
<p>Replace "Microsoft" with "W3Schools" in the paragraph below:</p> 
<button onclick="myFunction()">Try it</button> 
<p id="demo">Please visit Microsoft!</p> 
<script> 
function myFunction() { 
var str = document.getElementById("demo").innerHTML; 
var txt = str.replace("Microsoft","W3Schools"); 
document.getElementById("demo").innerHTML = txt; 
} 
</script></body></html> 
11. Converting to Upper and Lower Case 
A string is converted to upper case with toUpperCase(): 
<html><body>
<p>Convert string to upper case:</p> 
<button onclick="myFunction()">Try it</button> 
<p id="demo">Hello World!</p> 
<script> 
function myFunction() { 
var text = document.getElementById("demo").innerHTML; 
document.getElementById("demo").innerHTML = text.toUpperCase(); 
} 
</script></body></html> 
A string is converted to lower case with toLowerCase(): 
12. The concat() Method 
 concat() joins two or more strings: 
<html><body> 
<p>The concat() method joins two or more strings:</p> 
<p id="demo"></p> 
<script> 
var text1 = "Hello"; 
var text2 = "World!" 
document.getElementById("demo").innerHTML = text1.concat(" ",text2); 
</script></body></html> 
 The concat() method can be used instead of the plus operator. These two lines do the same: 
var text = "Hello" + " " + "World!"; 
var text = "Hello".concat(" ","World!"); 
13. Extracting String Characters 
· charAt(position) 
The charAt() Method 
 The charAt() method returns the character at a specified index (position) in a string: 
<html><body> 
<p>The charAt() method returns the character at a given position in a string:</p> 
<p id="demo"></p>
<script> 
var str = "HELLO WORLD"; 
document.getElementById("demo").innerHTML = str.charAt(0); 
</script></body></html> 
Date Objects: 
14. Displaying Dates 
<html><body> 
<p id="demo"></p> 
<script> 
document.getElementById("demo").innerHTML = Date(); 
</script> 
</body></html> 
 A date consists of a year, a month, a week, a day, a minute, a second, and a millisecond. 
 Date objects are created with the new Date() constructor. 
There are 4 ways of initiating a date: 
i. new Date() 
ii. new Date(milliseconds) 
iii. new Date(dateString) 
iv. new Date(year, month, day, hours, minutes, seconds, milliseconds) 
15. Using new Date (), without parameters, creates a new date object with the current date 
and time: 
<html><body> 
<p id="demo"></p> 
<script> 
var d = new Date(); 
document.getElementById("demo").innerHTML = d; 
</script></body></html> 
16. Using new Date (), with a date string, creates a new date object with the specified date 
and time: 
<html><body>
<p id="demo"></p> 
<script> 
var d = new Date("October 13, 2014 11:13:00"); 
document.getElementById("demo").innerHTML = d; 
</script></body></html> 
17. Using new Date(), with 7 numbers, creates a new date object with the 
specified date and time: The 7 numbers specify the year, month, day, hour, minute, 
second, and millisecond, in that order: 
<html><body> 
<p id="demo"></p> 
<script> 
var d = new Date(99,5,24,11,33,30,0); 
document.getElementById("demo").innerHTML = d; 
</script></body></html> 
18. Math Functions: 
 The Math object allows you to perform mathematical tasks. 
 One common use of the Math object is to create a random number: 
<html><body> 
<p>Math.random() returns a random number betwween 0 and 1.</p> 
<button onclick="myFunction()">Try it</button> 
<p id="demo"></p> 
<script> 
function myFunction() { 
document.getElementById("demo").innerHTML = Math.random(); 
} 
</script></body></html> 
19. Math.min() and Math.max() 
Math.min() can be used to find the lowest value in a list of arguments. 
<html><body> 
<p>Math.min() returns the lowest value.</p> 
<button onclick="myFunction()">Try it</button>
<p id="demo"></p> 
<script> 
function myFunction() { 
document.getElementById("demo").innerHTML = 
Math.min(0, 150, 30, 20, -8); 
} 
</script></body></html> 
20. Math.max() can be used to find the highest value in a list of arguments. 
<html> 
<body> 
<p>Math.max() returns the higest value.</p> 
<button onclick="myFunction()">Try it</button> 
<p id="demo"></p> 
<script> 
function myFunction() { 
document.getElementById("demo").innerHTML = 
Math.max(0, 150, 30, 20, -8); 
} 
</script></body></html> 
21. Math.round(): rounds a number to the nearest 
integer 
<html><body> 
<p>Math.round() rounds a number to its nearest integer.</p> 
<button onclick="myFunction()">Try it</button> 
<p id="demo"></p> 
<script> 
function myFunction() { 
document.getElementById("demo").innerHTML = Math.round(4.4); 
} 
</script></body></html> 
22. Math.floor(): rounds a number down to the nearest 
integer: 
<html><body> 
<p>Math.floor() rounds a number <strong>down</strong> to its nearest integer.</p>
<button onclick="myFunction()">Try it</button> 
<p id="demo"></p> 
<script> 
function myFunction() { 
document.getElementById("demo").innerHTML = Math.floor(4.7); 
} 
</script></body></html> 
23. Math Constants 
JavaScript provides 3 mathematical constants that can be accessed with the Math object: 
<html> 
<body> 
<p>Math constants are E, PI, SQR2, SQR1_2, LN2, LN10, LOG2E, LOG10E</p> 
<button onclick="myFunction()">Try it</button> 
<p id="demo"></p> 
<script> 
function myFunction() { 
document.getElementById("demo").innerHTML = 
Math.E + "<br>" + 
Math.PI + "<br>" + 
Math.SQRT2 + "<br>" ; 
} 
</script></body></html>
<button onclick="myFunction()">Try it</button> 
<p id="demo"></p> 
<script> 
function myFunction() { 
document.getElementById("demo").innerHTML = Math.floor(4.7); 
} 
</script></body></html> 
23. Math Constants 
JavaScript provides 3 mathematical constants that can be accessed with the Math object: 
<html> 
<body> 
<p>Math constants are E, PI, SQR2, SQR1_2, LN2, LN10, LOG2E, LOG10E</p> 
<button onclick="myFunction()">Try it</button> 
<p id="demo"></p> 
<script> 
function myFunction() { 
document.getElementById("demo").innerHTML = 
Math.E + "<br>" + 
Math.PI + "<br>" + 
Math.SQRT2 + "<br>" ; 
} 
</script></body></html>

More Related Content

What's hot

Improving the performance of Odoo deployments
Improving the performance of Odoo deploymentsImproving the performance of Odoo deployments
Improving the performance of Odoo deployments
Odoo
 
How to Bring Common UI Patterns to ADF
How to Bring Common UI Patterns to ADF How to Bring Common UI Patterns to ADF
How to Bring Common UI Patterns to ADF
Luc Bors
 
Config BuildConfig
Config BuildConfigConfig BuildConfig
Config BuildConfig
NexThoughts Technologies
 
Telephone billing system in c++
Telephone billing system in c++Telephone billing system in c++
Telephone billing system in c++
vikram mahendra
 
The secret unit testing tools no one ever told you about
The secret unit testing tools no one ever told you aboutThe secret unit testing tools no one ever told you about
The secret unit testing tools no one ever told you about
Dror Helper
 
Serverless Functions and Vue.js
Serverless Functions and Vue.jsServerless Functions and Vue.js
Serverless Functions and Vue.js
Sarah Drasner
 
mobl presentation @ IHomer
mobl presentation @ IHomermobl presentation @ IHomer
mobl presentation @ IHomerzefhemel
 
Workshop 5: JavaScript testing
Workshop 5: JavaScript testingWorkshop 5: JavaScript testing
Workshop 5: JavaScript testing
Visual Engineering
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolve
XSolve
 
Surfacing External Data Through Magnolia
Surfacing External Data Through MagnoliaSurfacing External Data Through Magnolia
Surfacing External Data Through Magnolia
SeanMcTex
 
Angular mix chrisnoring
Angular mix chrisnoringAngular mix chrisnoring
Angular mix chrisnoring
Christoffer Noring
 
Idoc script beginner guide
Idoc script beginner guide Idoc script beginner guide
Idoc script beginner guide
Vinay Kumar
 
Rooted 2010 ppp
Rooted 2010 pppRooted 2010 ppp
Rooted 2010 ppp
noc_313
 
JavaScript Functions
JavaScript Functions JavaScript Functions
JavaScript Functions
Reem Alattas
 
Spring 2.5
Spring 2.5Spring 2.5
Spring 2.5
Paul Bakker
 

What's hot (20)

Improving the performance of Odoo deployments
Improving the performance of Odoo deploymentsImproving the performance of Odoo deployments
Improving the performance of Odoo deployments
 
XML-RPC vs Psycopg2
XML-RPC vs Psycopg2XML-RPC vs Psycopg2
XML-RPC vs Psycopg2
 
How to Bring Common UI Patterns to ADF
How to Bring Common UI Patterns to ADF How to Bring Common UI Patterns to ADF
How to Bring Common UI Patterns to ADF
 
Config BuildConfig
Config BuildConfigConfig BuildConfig
Config BuildConfig
 
Ip project
Ip projectIp project
Ip project
 
Telephone billing system in c++
Telephone billing system in c++Telephone billing system in c++
Telephone billing system in c++
 
The secret unit testing tools no one ever told you about
The secret unit testing tools no one ever told you aboutThe secret unit testing tools no one ever told you about
The secret unit testing tools no one ever told you about
 
My java file
My java fileMy java file
My java file
 
Serverless Functions and Vue.js
Serverless Functions and Vue.jsServerless Functions and Vue.js
Serverless Functions and Vue.js
 
mobl presentation @ IHomer
mobl presentation @ IHomermobl presentation @ IHomer
mobl presentation @ IHomer
 
Workshop 5: JavaScript testing
Workshop 5: JavaScript testingWorkshop 5: JavaScript testing
Workshop 5: JavaScript testing
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolve
 
Surfacing External Data Through Magnolia
Surfacing External Data Through MagnoliaSurfacing External Data Through Magnolia
Surfacing External Data Through Magnolia
 
Angular mix chrisnoring
Angular mix chrisnoringAngular mix chrisnoring
Angular mix chrisnoring
 
Idoc script beginner guide
Idoc script beginner guide Idoc script beginner guide
Idoc script beginner guide
 
Rooted 2010 ppp
Rooted 2010 pppRooted 2010 ppp
Rooted 2010 ppp
 
Week 12 code
Week 12 codeWeek 12 code
Week 12 code
 
JavaScript Functions
JavaScript Functions JavaScript Functions
JavaScript Functions
 
MaintainStaffTable
MaintainStaffTableMaintainStaffTable
MaintainStaffTable
 
Spring 2.5
Spring 2.5Spring 2.5
Spring 2.5
 

Similar to 14922 java script built (1)

JavaScript Operators
JavaScript OperatorsJavaScript Operators
JavaScript Operators
Dr. Jasmine Beulah Gnanadurai
 
FYBSC IT Web Programming Unit III Core Javascript
FYBSC IT Web Programming Unit III  Core JavascriptFYBSC IT Web Programming Unit III  Core Javascript
FYBSC IT Web Programming Unit III Core Javascript
Arti Parab Academics
 
FYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III JavascriptFYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III Javascript
Arti Parab Academics
 
Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...
Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...
Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...
Ayes Chinmay
 
TypeScriptで書くAngularJS @ GDG神戸2014.8.23
TypeScriptで書くAngularJS @ GDG神戸2014.8.23TypeScriptで書くAngularJS @ GDG神戸2014.8.23
TypeScriptで書くAngularJS @ GDG神戸2014.8.23
Okuno Kentaro
 
Javascript 1
Javascript 1Javascript 1
Javascript 1
pavishkumarsingh
 
Bca sem 6 php practicals 1to12
Bca sem 6 php practicals 1to12Bca sem 6 php practicals 1to12
Bca sem 6 php practicals 1to12Hitesh Patel
 
JavaScript Training
JavaScript TrainingJavaScript Training
JavaScript Training
Ramindu Deshapriya
 
TYCS Ajax practicals sem VI
TYCS Ajax practicals sem VI TYCS Ajax practicals sem VI
TYCS Ajax practicals sem VI
yogita kachve
 
JavaScript lesson 1.pptx
JavaScript lesson 1.pptxJavaScript lesson 1.pptx
JavaScript lesson 1.pptx
MuqaddarNiazi1
 
Experience Manager 6 Developer Features - Highlights
Experience Manager 6 Developer Features - HighlightsExperience Manager 6 Developer Features - Highlights
Experience Manager 6 Developer Features - Highlights
Cédric Hüsler
 
JavaScript Lessons 2023
JavaScript Lessons 2023JavaScript Lessons 2023
JavaScript Lessons 2023
Laurence Svekis ✔
 
Polymer - pleasant client-side programming with web components
Polymer - pleasant client-side programming with web componentsPolymer - pleasant client-side programming with web components
Polymer - pleasant client-side programming with web components
psstoev
 
28,29. procedures subprocedure,type checking functions in VBScript
28,29. procedures  subprocedure,type checking functions in VBScript28,29. procedures  subprocedure,type checking functions in VBScript
28,29. procedures subprocedure,type checking functions in VBScript
VARSHAKUMARI49
 
bbyopenApp_Code.DS_StorebbyopenApp_CodeVBCodeGoogleMaps.docx
bbyopenApp_Code.DS_StorebbyopenApp_CodeVBCodeGoogleMaps.docxbbyopenApp_Code.DS_StorebbyopenApp_CodeVBCodeGoogleMaps.docx
bbyopenApp_Code.DS_StorebbyopenApp_CodeVBCodeGoogleMaps.docx
ikirkton
 
Introduction to Html5
Introduction to Html5Introduction to Html5
Introduction to Html5
www.netgains.org
 
Java script frame window
Java script frame windowJava script frame window
Java script frame windowH K
 
단일 페이지 인터페이스 웹/앱 개발
단일 페이지 인터페이스 웹/앱 개발단일 페이지 인터페이스 웹/앱 개발
단일 페이지 인터페이스 웹/앱 개발
동수 장
 

Similar to 14922 java script built (1) (20)

JavaScript Operators
JavaScript OperatorsJavaScript Operators
JavaScript Operators
 
FYBSC IT Web Programming Unit III Core Javascript
FYBSC IT Web Programming Unit III  Core JavascriptFYBSC IT Web Programming Unit III  Core Javascript
FYBSC IT Web Programming Unit III Core Javascript
 
FYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III JavascriptFYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III Javascript
 
Java Script
Java ScriptJava Script
Java Script
 
Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...
Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...
Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...
 
TypeScriptで書くAngularJS @ GDG神戸2014.8.23
TypeScriptで書くAngularJS @ GDG神戸2014.8.23TypeScriptで書くAngularJS @ GDG神戸2014.8.23
TypeScriptで書くAngularJS @ GDG神戸2014.8.23
 
Javascript 1
Javascript 1Javascript 1
Javascript 1
 
Bca sem 6 php practicals 1to12
Bca sem 6 php practicals 1to12Bca sem 6 php practicals 1to12
Bca sem 6 php practicals 1to12
 
JavaScript Training
JavaScript TrainingJavaScript Training
JavaScript Training
 
Django quickstart
Django quickstartDjango quickstart
Django quickstart
 
TYCS Ajax practicals sem VI
TYCS Ajax practicals sem VI TYCS Ajax practicals sem VI
TYCS Ajax practicals sem VI
 
JavaScript lesson 1.pptx
JavaScript lesson 1.pptxJavaScript lesson 1.pptx
JavaScript lesson 1.pptx
 
Experience Manager 6 Developer Features - Highlights
Experience Manager 6 Developer Features - HighlightsExperience Manager 6 Developer Features - Highlights
Experience Manager 6 Developer Features - Highlights
 
JavaScript Lessons 2023
JavaScript Lessons 2023JavaScript Lessons 2023
JavaScript Lessons 2023
 
Polymer - pleasant client-side programming with web components
Polymer - pleasant client-side programming with web componentsPolymer - pleasant client-side programming with web components
Polymer - pleasant client-side programming with web components
 
28,29. procedures subprocedure,type checking functions in VBScript
28,29. procedures  subprocedure,type checking functions in VBScript28,29. procedures  subprocedure,type checking functions in VBScript
28,29. procedures subprocedure,type checking functions in VBScript
 
bbyopenApp_Code.DS_StorebbyopenApp_CodeVBCodeGoogleMaps.docx
bbyopenApp_Code.DS_StorebbyopenApp_CodeVBCodeGoogleMaps.docxbbyopenApp_Code.DS_StorebbyopenApp_CodeVBCodeGoogleMaps.docx
bbyopenApp_Code.DS_StorebbyopenApp_CodeVBCodeGoogleMaps.docx
 
Introduction to Html5
Introduction to Html5Introduction to Html5
Introduction to Html5
 
Java script frame window
Java script frame windowJava script frame window
Java script frame window
 
단일 페이지 인터페이스 웹/앱 개발
단일 페이지 인터페이스 웹/앱 개발단일 페이지 인터페이스 웹/앱 개발
단일 페이지 인터페이스 웹/앱 개발
 

Recently uploaded

The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 

Recently uploaded (20)

The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 

14922 java script built (1)

  • 1. JavaScript Built-in objects JavaScript supports a number of built-in objects that extend the flexibility of the language. These objects are Date, Math, String, Array, and Object. 1. String Objects : <html> <body> <p id="demo"></p> <script> var carName1 = "Volvo XC60"; var carName2 = 'Volvo XC60'; var answer1 = "It's alright"; var answer2 = "He is called 'Johnny'"; var answer3 = 'He is called "Johnny"'; document.getElementById("demo").innerHTML = carName1 + "<br>" + carName2 + "<br>" + answer1 + "<br>" + answer2 + "<br>" + answer3; </script></body></html> 2. String Length: <html><body> <p id="demo"></p> <script> var txt="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; document.getElementById("demo").innerHTML = txt.length; </script></body></html> 3. Strings can be Objects  Normally, JavaScript strings are primitive values, created from literals: var firstName = "John"  But strings can also be defined as objects with the keyword new: var firstName = new String("John") <html><body>
  • 2. <p id="demo"></p> <script> var x = "John"; // x is a string var y = new String("John"); // y is an object document.getElementById("demo").innerHTML = typeof x + " " + typeof y; </script> </body></html> JavaScript string methods 4. The slice() Method  Slice() extracts a part of a string and returns the extracted part in a new string.  The method takes 2 parameters: the starting index (position), and the ending index (position).  This example slices out a portion of a string from position 7 to position 13: <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> If a parameter is negative, the position is counted from the end of the string. 5. This example slices out a portion of a string from position -12 to position -6: <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(-12,-6); </script></body></html>
  • 3. 6.If you omit the second parameter, the method will slice out the rest of the sting: <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); </script> </body></html> 7. or, counting from the end : <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(-12); </script></body></html> 8. The substring() Method  Substring () is similar to slice ().  The difference is that substring () cannot accept negative indexes. <html><body> <p>The substr() 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.substring(7,13); </script></body></html>
  • 4. 9. The substr() Method  substr() is similar to slice().  The difference is that the second parameter specifies the length of the extracted part. <html><body> <p>The substr() 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.substr(7,6); </script></body></html>  If the first parameter is negative, the position counts from the end of the string.  The second parameter can not be negative, because it defines the length.  If you omit the second parameter, substr() will slice out the rest of the string. 10. Replacing String Content  The replace() method replaces a specified value with another value in a string: <html><body> <p>Replace "Microsoft" with "W3Schools" in the paragraph below:</p> <button onclick="myFunction()">Try it</button> <p id="demo">Please visit Microsoft!</p> <script> function myFunction() { var str = document.getElementById("demo").innerHTML; var txt = str.replace("Microsoft","W3Schools"); document.getElementById("demo").innerHTML = txt; } </script></body></html> 11. Converting to Upper and Lower Case A string is converted to upper case with toUpperCase(): <html><body>
  • 5. <p>Convert string to upper case:</p> <button onclick="myFunction()">Try it</button> <p id="demo">Hello World!</p> <script> function myFunction() { var text = document.getElementById("demo").innerHTML; document.getElementById("demo").innerHTML = text.toUpperCase(); } </script></body></html> A string is converted to lower case with toLowerCase(): 12. The concat() Method  concat() joins two or more strings: <html><body> <p>The concat() method joins two or more strings:</p> <p id="demo"></p> <script> var text1 = "Hello"; var text2 = "World!" document.getElementById("demo").innerHTML = text1.concat(" ",text2); </script></body></html>  The concat() method can be used instead of the plus operator. These two lines do the same: var text = "Hello" + " " + "World!"; var text = "Hello".concat(" ","World!"); 13. Extracting String Characters · charAt(position) The charAt() Method  The charAt() method returns the character at a specified index (position) in a string: <html><body> <p>The charAt() method returns the character at a given position in a string:</p> <p id="demo"></p>
  • 6. <script> var str = "HELLO WORLD"; document.getElementById("demo").innerHTML = str.charAt(0); </script></body></html> Date Objects: 14. Displaying Dates <html><body> <p id="demo"></p> <script> document.getElementById("demo").innerHTML = Date(); </script> </body></html>  A date consists of a year, a month, a week, a day, a minute, a second, and a millisecond.  Date objects are created with the new Date() constructor. There are 4 ways of initiating a date: i. new Date() ii. new Date(milliseconds) iii. new Date(dateString) iv. new Date(year, month, day, hours, minutes, seconds, milliseconds) 15. Using new Date (), without parameters, creates a new date object with the current date and time: <html><body> <p id="demo"></p> <script> var d = new Date(); document.getElementById("demo").innerHTML = d; </script></body></html> 16. Using new Date (), with a date string, creates a new date object with the specified date and time: <html><body>
  • 7. <p id="demo"></p> <script> var d = new Date("October 13, 2014 11:13:00"); document.getElementById("demo").innerHTML = d; </script></body></html> 17. Using new Date(), with 7 numbers, creates a new date object with the specified date and time: The 7 numbers specify the year, month, day, hour, minute, second, and millisecond, in that order: <html><body> <p id="demo"></p> <script> var d = new Date(99,5,24,11,33,30,0); document.getElementById("demo").innerHTML = d; </script></body></html> 18. Math Functions:  The Math object allows you to perform mathematical tasks.  One common use of the Math object is to create a random number: <html><body> <p>Math.random() returns a random number betwween 0 and 1.</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("demo").innerHTML = Math.random(); } </script></body></html> 19. Math.min() and Math.max() Math.min() can be used to find the lowest value in a list of arguments. <html><body> <p>Math.min() returns the lowest value.</p> <button onclick="myFunction()">Try it</button>
  • 8. <p id="demo"></p> <script> function myFunction() { document.getElementById("demo").innerHTML = Math.min(0, 150, 30, 20, -8); } </script></body></html> 20. Math.max() can be used to find the highest value in a list of arguments. <html> <body> <p>Math.max() returns the higest value.</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("demo").innerHTML = Math.max(0, 150, 30, 20, -8); } </script></body></html> 21. Math.round(): rounds a number to the nearest integer <html><body> <p>Math.round() rounds a number to its nearest integer.</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("demo").innerHTML = Math.round(4.4); } </script></body></html> 22. Math.floor(): rounds a number down to the nearest integer: <html><body> <p>Math.floor() rounds a number <strong>down</strong> to its nearest integer.</p>
  • 9. <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("demo").innerHTML = Math.floor(4.7); } </script></body></html> 23. Math Constants JavaScript provides 3 mathematical constants that can be accessed with the Math object: <html> <body> <p>Math constants are E, PI, SQR2, SQR1_2, LN2, LN10, LOG2E, LOG10E</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("demo").innerHTML = Math.E + "<br>" + Math.PI + "<br>" + Math.SQRT2 + "<br>" ; } </script></body></html>
  • 10. <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("demo").innerHTML = Math.floor(4.7); } </script></body></html> 23. Math Constants JavaScript provides 3 mathematical constants that can be accessed with the Math object: <html> <body> <p>Math constants are E, PI, SQR2, SQR1_2, LN2, LN10, LOG2E, LOG10E</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("demo").innerHTML = Math.E + "<br>" + Math.PI + "<br>" + Math.SQRT2 + "<br>" ; } </script></body></html>