SlideShare una empresa de Scribd logo
1 de 14
JS-TYPES
大綱
 htmlString
 Number

 Object
 Array
 PlainObject
font-size

HTMLSTRING
 A string is designated htmlString in jQuery documentation when it is used
to represent one or more DOM elements, typically to be created and
inserted in the document.

 For explicit parsing of a string to HTML, the $.parseHTML() method is
available as of jQuery 1.8
 // Appends <b>hello</b>:
 $( "<b>hello</b>" ).appendTo( "body" );

 // Appends <b>hello</b>:
 $( "<b>hello</b>bye" ).appendTo( "body" );

 // Syntax error, unrecognized expression: bye<b>hello</b>
 $( "bye<b>hello</b>" ).appendTo( "body" );

 // Appends bye<b>hello</b>:
 $( $.parseHTML( "bye<b>hello</b>" ) ).appendTo( "body" );

 // Appends <b>hello</b>wait<b>bye</b>:
 $( "<b>hello</b>wait<b>bye</b>" ).appendTo( "body" );

 For explicit parsing of a string to HTML, use the $.parseHTML()
font-size

NUMBER
The type of a number is "number".
typeof 12 // "number"
typeof 3.543 // "number“

if a number is zero, it defaults to false:
!0 // true
!!0 // false
!1 // false
!-1 // false

Due to the implementation of numbers as double-precision values,
the following result is not an error:
0.1 + 0.2 // 0.30000000000000004
font-size

NUMBER
 Parsing Numbers
 parseInt and parseFloat help parsing strings into numbers. Both do
some implicit conversion if the base isn't specified:







parseInt( "123" ) = 123 // (implicit decimal)
parseInt( "010" ) = 8 // (implicit octal)
parseInt( "0xCAFE" ) = 51966 // (implicit hexadecimal)
parseInt( "010", 10 ) = 10 // (explicit decimal)
parseInt( "11", 2 ) = 3 // (explicit binary)
parseFloat( "10.10" ) = 10.1
font-size

NUMBER
 Numbers to Strings
 When appending numbers to string, the result is always a string.
The operator is the same, so be careful: If you want to add
numbers and then append them to a string, put parentheses
around them:





"" + 1 + 2; // "12"
"" + ( 1 + 2 ); // "3"
"" + 0.0000001; // "1e-7"
parseInt( 0.0000001 ); // 1 (!) , 1e-7 parseInt() -> 1

 Or you use the String class provided by javascript, which try to
parse a value as string
 String( 1 ) + String( 2 ); // "12"
 String( 1 + 2 ); // "3"
font-size

NUMBER
 NaN and Infinity
 Parsing something that isn't a number results in NaN. isNaN helps
to detect those cases:
 parseInt( "hello", 10 ) // NaN
 isNaN( parseInt("hello", 10) ) // true

 Division by zero results in Infinity:
 1 / 0 // Infinity

 Both NaN and Infinity are of type "number":
 typeof NaN // "number"
 typeof Infinity // "number“
font-size

NUMBER
 Note that NaN compares in a strange way:
 NaN == NaN // false (!)

 But:
 Infinity == Infinity // true
font-size

OBJECT
Everything in JavaScript is an object
var x = {};
var y = {
name: "Pete",
age: 15

};

The type of an object is "object":
typeof {} // "object“

Use Dot or Array Notation to write and read properties
var obj = {

name: "Pete",
age: 15
};
for( key in obj ) {
alert( "key is " + [ key ] + ", value is " + obj[ key ] );
}

Note that for-in-loop can be spoiled by extending Object.prototype so take care when using other
libraries.Use jQuery.each(obj, function( key, value ))
font-size

OBJECT
An object, no matter if it has properties or not, never defaults to
false:
!{} // false
!!{} // true
font-size

ARRAY
Arrays in JavaScript are mutable lists with a few built-in methods. You can
define arrays using the array literal:
var x = [];
var y = [ 1, 2, 3 ];

The type of an array is "object":
typeof []; // "object"
typeof [ 1, 2, 3 ]; // "object“

Reading and writing elements to an array uses the array-notation:
x[ 0 ] = 1;
y[ 2 ] // 3

 The length property can also be used to add elements to the end of an array
var x = [];
x.push( 1 );
x[ x.length ] = 2;
x[1000] = 1; // x.length = 1000
font-size

ARRAY
jQuery provides a generic each function to iterate over element of arrays, as well as properties of
objects:
var x = [ 1, 2, 3 ];
jQuery.each( x, function( index, value ) {
console.log( "index", index, "value", value );
});

The length property can also be used to add elements to the end of an array. That is equivalent to
using the push-method:
var x = [ 0, 3, 1, 2 ];
x.reverse() // x = [ 2, 1, 3, 0 ]
x.join(" – ") // "2 - 1 - 3 - 0"
x.pop() // pop 0 , x= [ 2, 1, 3 ]
x.unshift( -1 ) // newlength 4 , x = [ -1, 2, 1, 3 ]
x.shift() // remove -1 , x = [ 2, 1, 3 ]
x.sort() // [ 1, 2, 3 ]
x.splice( 1, 2 ) // remove 2,3 , x =[1 ]
An array, no matter if it has elements or not, never defaults to false:
![] // false
!![] // true
font-size

PLAINOBJECT
The PlainObject type is a JavaScript object containing zero or more keyvalue pairs. The plain object is, in other words, an Object object. It is
designated "plain" in jQuery documentation to distinguish it from other
kinds of JavaScript objects: for example, null, user-defined arrays, and host
objects such as document, all of which have a typeof value of "object." The
jQuery.isPlainObject() method identifies whether the passed argument is a
plain object or not, as demonstrated below:
var a = [];
var d = document;
var o = {};
typeof a; // object
typeof d; // object
typeof o; // object
jQuery.isPlainObject( a ); // false
jQuery.isPlainObject( d ); // false
jQuery.isPlainObject( o ); // true
font-size

REFERENCE
http://api.jquery.com/Types/

Más contenido relacionado

La actualidad más candente

Javascript built in String Functions
Javascript built in String FunctionsJavascript built in String Functions
Javascript built in String FunctionsAvanitrambadiya
 
JavaScript 101 - Class 1
JavaScript 101 - Class 1JavaScript 101 - Class 1
JavaScript 101 - Class 1Robert Pearce
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기진성 오
 
JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and ArraysWebStackAcademy
 
Java script introducation & basics
Java script introducation & basicsJava script introducation & basics
Java script introducation & basicsH K
 
Class 5 - PHP Strings
Class 5 - PHP StringsClass 5 - PHP Strings
Class 5 - PHP StringsAhmed Swilam
 
Opa presentation at GamesJs
Opa presentation at GamesJsOpa presentation at GamesJs
Opa presentation at GamesJsHenri Binsztok
 
Implementing a many-to-many Relationship with Slick
Implementing a many-to-many Relationship with SlickImplementing a many-to-many Relationship with Slick
Implementing a many-to-many Relationship with SlickHermann Hueck
 
Variables, expressions, standard types
 Variables, expressions, standard types  Variables, expressions, standard types
Variables, expressions, standard types Rubizza
 
Symfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 IntegrationSymfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 IntegrationJonathan Wage
 
Hardened JavaScript
Hardened JavaScriptHardened JavaScript
Hardened JavaScriptKrisKowal2
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & ArraysHenry Osborne
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objectsPhúc Đỗ
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrowPete McFarlane
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and FunctionsJussi Pohjolainen
 

La actualidad más candente (20)

Javascript built in String Functions
Javascript built in String FunctionsJavascript built in String Functions
Javascript built in String Functions
 
JavaScript 101 - Class 1
JavaScript 101 - Class 1JavaScript 101 - Class 1
JavaScript 101 - Class 1
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기
 
JavaScript - Chapter 10 - Strings and Arrays
 JavaScript - Chapter 10 - Strings and Arrays JavaScript - Chapter 10 - Strings and Arrays
JavaScript - Chapter 10 - Strings and Arrays
 
Java script arrays
Java script arraysJava script arrays
Java script arrays
 
Java script introducation & basics
Java script introducation & basicsJava script introducation & basics
Java script introducation & basics
 
Oop concepts in python
Oop concepts in pythonOop concepts in python
Oop concepts in python
 
Class 5 - PHP Strings
Class 5 - PHP StringsClass 5 - PHP Strings
Class 5 - PHP Strings
 
Opa presentation at GamesJs
Opa presentation at GamesJsOpa presentation at GamesJs
Opa presentation at GamesJs
 
Implementing a many-to-many Relationship with Slick
Implementing a many-to-many Relationship with SlickImplementing a many-to-many Relationship with Slick
Implementing a many-to-many Relationship with Slick
 
From OOP To FP Through A Practical Case
From OOP To FP Through A Practical CaseFrom OOP To FP Through A Practical Case
From OOP To FP Through A Practical Case
 
What are arrays in java script
What are arrays in java scriptWhat are arrays in java script
What are arrays in java script
 
Variables, expressions, standard types
 Variables, expressions, standard types  Variables, expressions, standard types
Variables, expressions, standard types
 
Symfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 IntegrationSymfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 Integration
 
Hardened JavaScript
Hardened JavaScriptHardened JavaScript
Hardened JavaScript
 
Quebec pdo
Quebec pdoQuebec pdo
Quebec pdo
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & Arrays
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objects
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrow
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and Functions
 

Similar a Js types

Stuff you didn't know about action script
Stuff you didn't know about action scriptStuff you didn't know about action script
Stuff you didn't know about action scriptChristophe Herreman
 
Ajax and JavaScript Bootcamp
Ajax and JavaScript BootcampAjax and JavaScript Bootcamp
Ajax and JavaScript BootcampAndreCharland
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypesVarun C M
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side JavascriptJulie Iskander
 
Java script
 Java script Java script
Java scriptbosybosy
 
JQuery Presentation
JQuery PresentationJQuery Presentation
JQuery PresentationSony Jain
 
10. session 10 loops and arrays
10. session 10   loops and arrays10. session 10   loops and arrays
10. session 10 loops and arraysPhúc Đỗ
 
ES6 General Introduction
ES6 General IntroductionES6 General Introduction
ES6 General IntroductionThomas Johnston
 
JavaScript Workshop
JavaScript WorkshopJavaScript Workshop
JavaScript WorkshopPamela Fox
 
Java script objects 1
Java script objects 1Java script objects 1
Java script objects 1H K
 
An introduction to javascript
An introduction to javascriptAn introduction to javascript
An introduction to javascripttonyh1
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Jonas Bonér
 

Similar a Js types (20)

Stuff you didn't know about action script
Stuff you didn't know about action scriptStuff you didn't know about action script
Stuff you didn't know about action script
 
Ajax and JavaScript Bootcamp
Ajax and JavaScript BootcampAjax and JavaScript Bootcamp
Ajax and JavaScript Bootcamp
 
Javascript
JavascriptJavascript
Javascript
 
Java script
Java scriptJava script
Java script
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
 
Java script
 Java script Java script
Java script
 
jQuery introduction
jQuery introductionjQuery introduction
jQuery introduction
 
Java Script Introduction
Java Script IntroductionJava Script Introduction
Java Script Introduction
 
JQuery Presentation
JQuery PresentationJQuery Presentation
JQuery Presentation
 
10. session 10 loops and arrays
10. session 10   loops and arrays10. session 10   loops and arrays
10. session 10 loops and arrays
 
ES6 General Introduction
ES6 General IntroductionES6 General Introduction
ES6 General Introduction
 
Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
 
JavaScript Workshop
JavaScript WorkshopJavaScript Workshop
JavaScript Workshop
 
"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
 
Java script objects 1
Java script objects 1Java script objects 1
Java script objects 1
 
JavaScript.pptx
JavaScript.pptxJavaScript.pptx
JavaScript.pptx
 
An introduction to javascript
An introduction to javascriptAn introduction to javascript
An introduction to javascript
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)
 

Más de LearningTech

Más de LearningTech (20)

vim
vimvim
vim
 
PostCss
PostCssPostCss
PostCss
 
ReactJs
ReactJsReactJs
ReactJs
 
Docker
DockerDocker
Docker
 
Semantic ui
Semantic uiSemantic ui
Semantic ui
 
node.js errors
node.js errorsnode.js errors
node.js errors
 
Process control nodejs
Process control nodejsProcess control nodejs
Process control nodejs
 
Expression tree
Expression treeExpression tree
Expression tree
 
SQL 效能調校
SQL 效能調校SQL 效能調校
SQL 效能調校
 
flexbox report
flexbox reportflexbox report
flexbox report
 
Vic weekly learning_20160504
Vic weekly learning_20160504Vic weekly learning_20160504
Vic weekly learning_20160504
 
Reflection &amp; activator
Reflection &amp; activatorReflection &amp; activator
Reflection &amp; activator
 
Peggy markdown
Peggy markdownPeggy markdown
Peggy markdown
 
Node child process
Node child processNode child process
Node child process
 
20160415ken.lee
20160415ken.lee20160415ken.lee
20160415ken.lee
 
Peggy elasticsearch應用
Peggy elasticsearch應用Peggy elasticsearch應用
Peggy elasticsearch應用
 
Expression tree
Expression treeExpression tree
Expression tree
 
Vic weekly learning_20160325
Vic weekly learning_20160325Vic weekly learning_20160325
Vic weekly learning_20160325
 
D3js learning tips
D3js learning tipsD3js learning tips
D3js learning tips
 
git command
git commandgit command
git command
 

Último

How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 

Último (20)

How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 

Js types

  • 2. 大綱  htmlString  Number  Object  Array  PlainObject
  • 3. font-size HTMLSTRING  A string is designated htmlString in jQuery documentation when it is used to represent one or more DOM elements, typically to be created and inserted in the document.  For explicit parsing of a string to HTML, the $.parseHTML() method is available as of jQuery 1.8  // Appends <b>hello</b>:  $( "<b>hello</b>" ).appendTo( "body" );  // Appends <b>hello</b>:  $( "<b>hello</b>bye" ).appendTo( "body" );  // Syntax error, unrecognized expression: bye<b>hello</b>  $( "bye<b>hello</b>" ).appendTo( "body" );  // Appends bye<b>hello</b>:  $( $.parseHTML( "bye<b>hello</b>" ) ).appendTo( "body" );  // Appends <b>hello</b>wait<b>bye</b>:  $( "<b>hello</b>wait<b>bye</b>" ).appendTo( "body" );  For explicit parsing of a string to HTML, use the $.parseHTML()
  • 4. font-size NUMBER The type of a number is "number". typeof 12 // "number" typeof 3.543 // "number“ if a number is zero, it defaults to false: !0 // true !!0 // false !1 // false !-1 // false Due to the implementation of numbers as double-precision values, the following result is not an error: 0.1 + 0.2 // 0.30000000000000004
  • 5. font-size NUMBER  Parsing Numbers  parseInt and parseFloat help parsing strings into numbers. Both do some implicit conversion if the base isn't specified:       parseInt( "123" ) = 123 // (implicit decimal) parseInt( "010" ) = 8 // (implicit octal) parseInt( "0xCAFE" ) = 51966 // (implicit hexadecimal) parseInt( "010", 10 ) = 10 // (explicit decimal) parseInt( "11", 2 ) = 3 // (explicit binary) parseFloat( "10.10" ) = 10.1
  • 6. font-size NUMBER  Numbers to Strings  When appending numbers to string, the result is always a string. The operator is the same, so be careful: If you want to add numbers and then append them to a string, put parentheses around them:     "" + 1 + 2; // "12" "" + ( 1 + 2 ); // "3" "" + 0.0000001; // "1e-7" parseInt( 0.0000001 ); // 1 (!) , 1e-7 parseInt() -> 1  Or you use the String class provided by javascript, which try to parse a value as string  String( 1 ) + String( 2 ); // "12"  String( 1 + 2 ); // "3"
  • 7. font-size NUMBER  NaN and Infinity  Parsing something that isn't a number results in NaN. isNaN helps to detect those cases:  parseInt( "hello", 10 ) // NaN  isNaN( parseInt("hello", 10) ) // true  Division by zero results in Infinity:  1 / 0 // Infinity  Both NaN and Infinity are of type "number":  typeof NaN // "number"  typeof Infinity // "number“
  • 8. font-size NUMBER  Note that NaN compares in a strange way:  NaN == NaN // false (!)  But:  Infinity == Infinity // true
  • 9. font-size OBJECT Everything in JavaScript is an object var x = {}; var y = { name: "Pete", age: 15 }; The type of an object is "object": typeof {} // "object“ Use Dot or Array Notation to write and read properties var obj = { name: "Pete", age: 15 }; for( key in obj ) { alert( "key is " + [ key ] + ", value is " + obj[ key ] ); } Note that for-in-loop can be spoiled by extending Object.prototype so take care when using other libraries.Use jQuery.each(obj, function( key, value ))
  • 10. font-size OBJECT An object, no matter if it has properties or not, never defaults to false: !{} // false !!{} // true
  • 11. font-size ARRAY Arrays in JavaScript are mutable lists with a few built-in methods. You can define arrays using the array literal: var x = []; var y = [ 1, 2, 3 ]; The type of an array is "object": typeof []; // "object" typeof [ 1, 2, 3 ]; // "object“ Reading and writing elements to an array uses the array-notation: x[ 0 ] = 1; y[ 2 ] // 3  The length property can also be used to add elements to the end of an array var x = []; x.push( 1 ); x[ x.length ] = 2; x[1000] = 1; // x.length = 1000
  • 12. font-size ARRAY jQuery provides a generic each function to iterate over element of arrays, as well as properties of objects: var x = [ 1, 2, 3 ]; jQuery.each( x, function( index, value ) { console.log( "index", index, "value", value ); }); The length property can also be used to add elements to the end of an array. That is equivalent to using the push-method: var x = [ 0, 3, 1, 2 ]; x.reverse() // x = [ 2, 1, 3, 0 ] x.join(" – ") // "2 - 1 - 3 - 0" x.pop() // pop 0 , x= [ 2, 1, 3 ] x.unshift( -1 ) // newlength 4 , x = [ -1, 2, 1, 3 ] x.shift() // remove -1 , x = [ 2, 1, 3 ] x.sort() // [ 1, 2, 3 ] x.splice( 1, 2 ) // remove 2,3 , x =[1 ] An array, no matter if it has elements or not, never defaults to false: ![] // false !![] // true
  • 13. font-size PLAINOBJECT The PlainObject type is a JavaScript object containing zero or more keyvalue pairs. The plain object is, in other words, an Object object. It is designated "plain" in jQuery documentation to distinguish it from other kinds of JavaScript objects: for example, null, user-defined arrays, and host objects such as document, all of which have a typeof value of "object." The jQuery.isPlainObject() method identifies whether the passed argument is a plain object or not, as demonstrated below: var a = []; var d = document; var o = {}; typeof a; // object typeof d; // object typeof o; // object jQuery.isPlainObject( a ); // false jQuery.isPlainObject( d ); // false jQuery.isPlainObject( o ); // true