SlideShare une entreprise Scribd logo
1  sur  10
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>

Contenu connexe

Tendances

Improving the performance of Odoo deployments
Improving the performance of Odoo deploymentsImproving the performance of Odoo deployments
Improving the performance of Odoo deploymentsOdoo
 
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
 
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 aboutDror Helper
 
Serverless Functions and Vue.js
Serverless Functions and Vue.jsServerless Functions and Vue.js
Serverless Functions and Vue.jsSarah 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 testingVisual 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 / XSolveXSolve
 
Surfacing External Data Through Magnolia
Surfacing External Data Through MagnoliaSurfacing External Data Through Magnolia
Surfacing External Data Through MagnoliaSeanMcTex
 
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 pppnoc_313
 
JavaScript Functions
JavaScript Functions JavaScript Functions
JavaScript Functions Reem Alattas
 

Tendances (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
 

Similaire à 14922 java script built (1)

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 JavascriptArti 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 JavascriptArti 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.23Okuno Kentaro
 
Bca sem 6 php practicals 1to12
Bca sem 6 php practicals 1to12Bca sem 6 php practicals 1to12
Bca sem 6 php practicals 1to12Hitesh Patel
 
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.pptxMuqaddarNiazi1
 
Experience Manager 6 Developer Features - Highlights
Experience Manager 6 Developer Features - HighlightsExperience Manager 6 Developer Features - Highlights
Experience Manager 6 Developer Features - HighlightsCédric Hüsler
 
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 componentspsstoev
 
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 VBScriptVARSHAKUMARI49
 
bbyopenApp_Code.DS_StorebbyopenApp_CodeVBCodeGoogleMaps.docx
bbyopenApp_Code.DS_StorebbyopenApp_CodeVBCodeGoogleMaps.docxbbyopenApp_Code.DS_StorebbyopenApp_CodeVBCodeGoogleMaps.docx
bbyopenApp_Code.DS_StorebbyopenApp_CodeVBCodeGoogleMaps.docxikirkton
 
Java script frame window
Java script frame windowJava script frame window
Java script frame windowH K
 
단일 페이지 인터페이스 웹/앱 개발
단일 페이지 인터페이스 웹/앱 개발단일 페이지 인터페이스 웹/앱 개발
단일 페이지 인터페이스 웹/앱 개발동수 장
 

Similaire à 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
 
단일 페이지 인터페이스 웹/앱 개발
단일 페이지 인터페이스 웹/앱 개발단일 페이지 인터페이스 웹/앱 개발
단일 페이지 인터페이스 웹/앱 개발
 

Dernier

General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 

Dernier (20)

General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 

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>