SlideShare a Scribd company logo
1 of 25
Download to read offline
JavaScript for ABAP Programmers
Data Types
Chris Whealy / The RIG
ABAP
Strongly typed
Syntax similar to COBOL
Block Scope
No equivalent concept
OO using class based inheritance
Imperative programming

JavaScript
Weakly typed
Syntax derived from Java
Lexical Scope
Functions are 1st class citizens
OO using referential inheritance
Imperative or Functional programming
Strongly Typed vs. Weakly Typed Languages
There are two schools of thought for determining how data should be stored in variables:
ā€¢ ABAP uses Strong (or Static) Typing
Apart from field symbols, all ABAP variables
must have their data type defined at declaration
time

Ā© 2013 SAP AG. All rights reserved.

3
Strongly Typed vs. Weakly Typed Languages
There are two schools of thought for determining how data should be stored in variables:
ā€¢ ABAP uses Strong (or Static) Typing
ā€¢ JavaScript uses Weak (or Dynamic) Typing
Apart from field symbols, all ABAP variables
A variable takes on the data type of whatever
must have their data type defined at declaration
value it currently holds
time

Ā© 2013 SAP AG. All rights reserved.

4
Strongly Typed vs. Weakly Typed Languages
There are two schools of thought for determining how data should be stored in variables:
ā€¢ ABAP uses Strong (or Static) Typing
ā€¢ JavaScript uses Weak (or Dynamic) Typing
Apart from field symbols, all ABAP variables
A variable takes on the data type of whatever
must have their data type defined at declaration
value it currently holds
time
ā€¢ Pros and Cons of Strong Typing

+ Data type errors can be trapped at compile time
- Rigid type systems reduce language flexibility

Ā© 2013 SAP AG. All rights reserved.

5
Strongly Typed vs. Weakly Typed Languages
There are two schools of thought for determining how data should be stored in variables:
ā€¢ ABAP uses Strong (or Static) Typing
ā€¢ JavaScript uses Weak (or Dynamic) Typing
Apart from field symbols, all ABAP variables
A variable takes on the data type of whatever
must have their data type defined at declaration
value it currently holds
time
ā€¢ Pros and Cons of Strong Typing
ā€¢ Pros and Cons of Weak Typing

+ Data type errors can be trapped at compile time
- Rigid type systems reduce language flexibility

- Data type errors can only be trapped at runtime
+ Highly flexible type system allows for a dynamic
style of coding

Ā© 2013 SAP AG. All rights reserved.

6
Strongly Typed vs. Weakly Typed Languages
There are two schools of thought for determining how data should be stored in variables:
ā€¢ ABAP uses Strong (or Static) Typing
ā€¢ JavaScript uses Weak (or Dynamic) Typing
Apart from field symbols, all ABAP variables
A variable takes on the data type of whatever
must have their data type defined at declaration
value it currently holds
time
ā€¢ Pros and Cons of Strong Typing
ā€¢ Pros and Cons of Weak Typing

+ Data type errors can be trapped at compile time
- Rigid type systems reduce language flexibility

- Data type errors can only be trapped at runtime
+ Highly flexible type system allows for a dynamic
style of coding

Compiled languages (E.G. ABAP, Java, C) tend to use strong typing, whereas interpreted scripting
languages (E.G. JavaScript, Ruby, Python) tend to use weak typing.

Ā© 2013 SAP AG. All rights reserved.

7
JavaScript Data Types: Overview
In JavaScript, there are only 6 data types.
At any one time the value of a variable belongs to one and only one of the following data types.

Data Type

This value of this variableā€¦

Null

Is explicitly defined as having no value

Undefined

Is indeterminate

Boolean

Is either true or false

String

Is an immutable collection of zero or more Unicode characters

Number

Can be used in mathematical operations

Object

Is an unordered collection of name/value pairs

Ā© 2013 SAP AG. All rights reserved.

8
JavaScript Data Types 1/3
In the coding, the data types are specified as follows:
// -----------------------------------------------------------------------------------------------// Special
null;
// Indicates an explicit non-value
undefined;
// Indicates an indeterminate value (E.G. a variable is declared but not initialised)

Ā© 2013 SAP AG. All rights reserved.

9
JavaScript Data Types 1/3
In the coding, the data types are specified as follows:
// -----------------------------------------------------------------------------------------------// Special
null;
// Indicates an explicit non-value
undefined;
// Indicates an indeterminate value (E.G. a variable is declared but not initialised)
// -----------------------------------------------------------------------------------------------// Boolean
true;
false;

Ā© 2013 SAP AG. All rights reserved.

10
JavaScript Data Types 1/3
In the coding, the data types are specified as follows:
// -----------------------------------------------------------------------------------------------// Special
null;
// Indicates an explicit non-value
undefined;
// Indicates an indeterminate value (E.G. a variable is declared but not initialised)
// -----------------------------------------------------------------------------------------------// Boolean
true;
false;
// -----------------------------------------------------------------------------------------------// String ā€“ contains zero or more Unicode characters
'Bazinga!';
// Can be delimited by either single quotes
"";
// Or double quotes

Ā© 2013 SAP AG. All rights reserved.

11
JavaScript Data Types 2/3
In the coding, the data types are specified as follows:
// -----------------------------------------------------------------------------------------------// Number
3.1415926;
// Stored as 64-bit floating point number
1;
// Be careful, this is stored as floating point value, not an integer!

Ā© 2013 SAP AG. All rights reserved.

12
JavaScript Data Types 2/3
In the coding, the data types are specified as follows:
// -----------------------------------------------------------------------------------------------// Number
3.1415926;
// Stored as 64-bit floating point number
1;
// Be careful, this is stored as floating point value, not an integer!
// Warning! All the usual problems associated with trying to represent decimal values in binary
// floating point format still apply in JavaScript!
var result = 0.1 + 0.2;
result;
// ļƒ  0.30000000000000004, not 0.3 (Decimal 0.1 has no exact binary equivalent)

Ā© 2013 SAP AG. All rights reserved.

13
JavaScript Data Types 2/3
In the coding, the data types are specified as follows:
// -----------------------------------------------------------------------------------------------// Number
3.1415926;
// Stored as 64-bit floating point number
1;
// Be careful, this is stored as floating point value, not an integer!
// Warning! All the usual problems associated with trying to represent decimal values in binary
// floating point format still apply in JavaScript!
var result = 0.1 + 0.2;
result;
// ļƒ  0.30000000000000004, not 0.3 (Decimal 0.1 has no exact binary equivalent)
// Special numerical values that could be returned in the event of illegal mathematical operations
// (These values are actually stored as properties of the Global Object)
NaN;
// 'Not a Number' E.G. 1/'cat' ļƒ  NaN
Infinity;
// The result of division by zero

Ā© 2013 SAP AG. All rights reserved.

14
JavaScript Data Types 3/3
In addition to the basic data type of Object, JavaScript provides several built-in objects that behave as
if they were composite data types. E.G. Array, Date, Function, Math and RegEx etc.
// -----------------------------------------------------------------------------------------------// Object. Zero or more unordered name:value pairs of any data type delimited by curly braces
{ pet1: 'cat',
pet2: 'dog' };

Ā© 2013 SAP AG. All rights reserved.

15
JavaScript Data Types 3/3
In addition to the basic data type of Object, JavaScript provides several built-in objects that behave as
if they were composite data types. E.G. Array, Date, Function, Math and RegEx etc.
// -----------------------------------------------------------------------------------------------// Object. Zero or more unordered name:value pairs of any data type delimited by curly braces
{ pet1: 'cat',
pet2: 'dog' };
// Array object. Zero or more values of any data type accessed by a numerical, 0 based index
[1,2,3,4,5];

Ā© 2013 SAP AG. All rights reserved.

16
JavaScript Data Types 3/3
In addition to the basic data type of Object, JavaScript provides several built-in objects that behave as
if they were composite data types. E.G. Array, Date, Function, Math and RegEx etc.
// -----------------------------------------------------------------------------------------------// Object. Zero or more unordered name:value pairs of any data type delimited by curly braces
{ pet1: 'cat',
pet2: 'dog' };
// Array object. Zero or more values of any data type accessed by a numerical, 0 based index
[1,2,3,4,5];
// Function object. A special object that has both properties and executable content
function() { /* statements */ }

Ā© 2013 SAP AG. All rights reserved.

17
JavaScript Data Types 3/3
In addition to the basic data type of Object, JavaScript provides several built-in objects that behave as
if they were composite data types. E.G. Array, Date, Function, Math and RegEx etc.
// -----------------------------------------------------------------------------------------------// Object. Zero or more unordered name:value pairs of any data type delimited by curly braces
{ pet1: 'cat',
pet2: 'dog' };
// Array object. Zero or more values of any data type accessed by a numerical, 0 based index
[1,2,3,4,5];
// Function object. A special object that has both properties and executable content
function() { /* statements */ }
// Math object. Contains many useful mathematical functions and constants
Math.PI; // ļƒ  3.141592653589793

Ā© 2013 SAP AG. All rights reserved.

18
JavaScript Data Types 3/3
In addition to the basic data type of Object, JavaScript provides several built-in objects that behave as
if they were composite data types. E.G. Array, Date, Function, Math and RegEx etc.
// -----------------------------------------------------------------------------------------------// Object. Zero or more unordered name:value pairs of any data type delimited by curly braces
{ pet1: 'cat',
pet2: 'dog' };
// Array object. Zero or more values of any data type accessed by a numerical, 0 based index
[1,2,3,4,5];
// Function object. A special object that has both properties and executable content
function() { /* statements */ }
// Math object. Contains many useful mathematical functions and constants
Math.PI; // ļƒ  3.141592653589793
// Regular Expression Object. A tool for specifying and extracting patterns of text within a string
/^(?:([A-Za-z]+):)?(/{0,3})([0-9.-A-Za-z]+)(?::(d+))?(?:/([^?#]*))?(?:?([^#]*))?(?:#(.*))?$/;

Ā© 2013 SAP AG. All rights reserved.

19
JavaScript Data Types 3/3
In addition to the basic data type of Object, JavaScript provides several built-in objects that behave as
if they were composite data types. E.G. Array, Date, Function, Math and RegEx etc.
// -----------------------------------------------------------------------------------------------// Object. Zero or more unordered name:value pairs of any data type delimited by curly braces
{ pet1: 'cat',
pet2: 'dog' };
// Array object. Zero or more values of any data type accessed by a numerical, 0 based index
[1,2,3,4,5];
// Function object. A special object that has both properties and executable content
function() { /* statements */ }
// Math object. Contains many useful mathematical functions and constants
Math.PI; // ļƒ  3.141592653589793
// Regular Expression Object. A tool for specifying and extracting patterns of text within a string
// Regular expressions are sometimes confused with Egyptian hieroglyphics... :-)

Ā© 2013 SAP AG. All rights reserved.

20
Variables and Data Types
In weakly typed languages such as JavaScript, there is no concept of declaring that a variable should hold data of
a particular type. The data type of a variable is determined simply by the value it currently holds.
// A weakly typed language means that data types are determined
// dynamically at runtime, not statically at design time
var whoAmI = 'Hello world';

Ā© 2013 SAP AG. All rights reserved.

// Variable 'whoAmI' is both declared & assigned a string value

21
Variables and Data Types
In weakly typed languages such as JavaScript, there is no concept of declaring that a variable should hold data of
a particular type. The data type of a variable is determined simply by the value it currently holds.
// A weakly typed language means that data types are determined
// dynamically at runtime, not statically at design time
var whoAmI = 'Hello world';

// Variable 'whoAmI' is both declared & assigned a string value

whoAmI = 1.61792;
whoAmI = [1,2,3,4,5];

// Now it's a number
// Now it's an array

Ā© 2013 SAP AG. All rights reserved.

22
Variables and Data Types
In weakly typed languages such as JavaScript, there is no concept of declaring that a variable should hold data of
a particular type. The data type of a variable is determined simply by the value it currently holds.
// A weakly typed language means that data types are determined
// dynamically at runtime, not statically at design time
var whoAmI = 'Hello world';

// Variable 'whoAmI' is both declared & assigned a string value

whoAmI = 1.61792;
whoAmI = [1,2,3,4,5];

// Now it's a number
// Now it's an array

whoAmI = true;

// Now it's a Boolean

Ā© 2013 SAP AG. All rights reserved.

23
Variables and Data Types
In weakly typed languages such as JavaScript, there is no concept of declaring that a variable should hold data of
a particular type. The data type of a variable is determined simply by the value it currently holds.
// A weakly typed language means that data types are determined
// dynamically at runtime, not statically at design time
var whoAmI = 'Hello world';

// Variable 'whoAmI' is both declared & assigned a string value

whoAmI = 1.61792;
whoAmI = [1,2,3,4,5];

// Now it's a number
// Now it's an array

whoAmI = true;

// Now it's a Boolean

whoAmI = {
// Now it's an object
someProperty: 'Hello world'
}

Ā© 2013 SAP AG. All rights reserved.

24
Variables and Data Types
In weakly typed languages such as JavaScript, there is no concept of declaring that a variable should hold data of
a particular type. The data type of a variable is determined simply by the value it currently holds.
// A weakly typed language means that data types are determined
// dynamically at runtime, not statically at design time
var whoAmI = 'Hello world';

// Variable 'whoAmI' is both declared & assigned a string value

whoAmI = 1.61792;
whoAmI = [1,2,3,4,5];

// Now it's a number
// Now it's an array

whoAmI = true;

// Now it's a Boolean

whoAmI = {
// Now it's an object
someProperty: 'Hello world'
}
whoAmI = function() { };

Ā© 2013 SAP AG. All rights reserved.

// Now it's a...you get the idea

25

More Related Content

What's hot

What's hot (20)

Aem dispatcher ā€“ tips & tricks
Aem dispatcher ā€“ tips & tricksAem dispatcher ā€“ tips & tricks
Aem dispatcher ā€“ tips & tricks
Ā 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6
Ā 
Ansible roles done right
Ansible roles done rightAnsible roles done right
Ansible roles done right
Ā 
JavaScript Fetch API
JavaScript Fetch APIJavaScript Fetch API
JavaScript Fetch API
Ā 
AEM and Sling
AEM and SlingAEM and Sling
AEM and Sling
Ā 
Fetch API Talk
Fetch API TalkFetch API Talk
Fetch API Talk
Ā 
routing.pptx
routing.pptxrouting.pptx
routing.pptx
Ā 
Clean code in JavaScript
Clean code in JavaScriptClean code in JavaScript
Clean code in JavaScript
Ā 
Swift Tutorial Part 1. The Complete Guide For Swift Programming Language
Swift Tutorial Part 1. The Complete Guide For Swift Programming LanguageSwift Tutorial Part 1. The Complete Guide For Swift Programming Language
Swift Tutorial Part 1. The Complete Guide For Swift Programming Language
Ā 
Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition!
Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition! Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition!
Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition!
Ā 
Functional programming
Functional programmingFunctional programming
Functional programming
Ā 
Java Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overridingJava Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overriding
Ā 
Basic Concepts Of OOPS/OOPS in Java,C++
Basic Concepts Of OOPS/OOPS in Java,C++Basic Concepts Of OOPS/OOPS in Java,C++
Basic Concepts Of OOPS/OOPS in Java,C++
Ā 
Complete Java Course
Complete Java CourseComplete Java Course
Complete Java Course
Ā 
Angular 2 observables
Angular 2 observablesAngular 2 observables
Angular 2 observables
Ā 
Spring Native and Spring AOT
Spring Native and Spring AOTSpring Native and Spring AOT
Spring Native and Spring AOT
Ā 
Asynchronous javascript
 Asynchronous javascript Asynchronous javascript
Asynchronous javascript
Ā 
AEM & Single Page Applications (SPAs) 101
AEM & Single Page Applications (SPAs) 101AEM & Single Page Applications (SPAs) 101
AEM & Single Page Applications (SPAs) 101
Ā 
Angular and The Case for RxJS
Angular and The Case for RxJSAngular and The Case for RxJS
Angular and The Case for RxJS
Ā 
Sightly - Part 2
Sightly - Part 2Sightly - Part 2
Sightly - Part 2
Ā 

Similar to JavaScript for ABAP Programmers - 2/7 Data Types

Java script session 3
Java script session 3Java script session 3
Java script session 3
Saif Ullah Dar
Ā 
Apache pig power_tools_by_viswanath_gangavaram_r&d_dsg_i_labs
Apache pig power_tools_by_viswanath_gangavaram_r&d_dsg_i_labsApache pig power_tools_by_viswanath_gangavaram_r&d_dsg_i_labs
Apache pig power_tools_by_viswanath_gangavaram_r&d_dsg_i_labs
Viswanath Gangavaram
Ā 
SAP ABAP Latest Interview Questions
SAP ABAP Latest  Interview Questions SAP ABAP Latest  Interview Questions
SAP ABAP Latest Interview Questions
piyushchawala
Ā 
2015 01-17 Lambda Architecture with Apache Spark, NextML Conference
2015 01-17 Lambda Architecture with Apache Spark, NextML Conference2015 01-17 Lambda Architecture with Apache Spark, NextML Conference
2015 01-17 Lambda Architecture with Apache Spark, NextML Conference
DB Tsai
Ā 

Similar to JavaScript for ABAP Programmers - 2/7 Data Types (20)

Java platform
Java platformJava platform
Java platform
Ā 
Java script session 3
Java script session 3Java script session 3
Java script session 3
Ā 
3 jf h-linearequations
3  jf h-linearequations3  jf h-linearequations
3 jf h-linearequations
Ā 
ABAP Coding Standards Reference Guide
ABAP Coding Standards Reference GuideABAP Coding Standards Reference Guide
ABAP Coding Standards Reference Guide
Ā 
Unit 4 - Basic ABAP statements, ABAP Structures and ABAP Logical Expressions
Unit 4 - Basic ABAP statements, ABAP Structures and ABAP Logical ExpressionsUnit 4 - Basic ABAP statements, ABAP Structures and ABAP Logical Expressions
Unit 4 - Basic ABAP statements, ABAP Structures and ABAP Logical Expressions
Ā 
Apache pig power_tools_by_viswanath_gangavaram_r&d_dsg_i_labs
Apache pig power_tools_by_viswanath_gangavaram_r&d_dsg_i_labsApache pig power_tools_by_viswanath_gangavaram_r&d_dsg_i_labs
Apache pig power_tools_by_viswanath_gangavaram_r&d_dsg_i_labs
Ā 
Graal and Truffle: One VM to Rule Them All
Graal and Truffle: One VM to Rule Them AllGraal and Truffle: One VM to Rule Them All
Graal and Truffle: One VM to Rule Them All
Ā 
Evaluate And Analysis of ALGOL, ADA ,PASCAL Programming Languages
Evaluate And Analysis of ALGOL, ADA ,PASCAL Programming Languages Evaluate And Analysis of ALGOL, ADA ,PASCAL Programming Languages
Evaluate And Analysis of ALGOL, ADA ,PASCAL Programming Languages
Ā 
Oracle to Amazon Aurora Migration, Step by Step - AWS Online Tech Talks
Oracle to Amazon Aurora Migration, Step by Step - AWS Online Tech TalksOracle to Amazon Aurora Migration, Step by Step - AWS Online Tech Talks
Oracle to Amazon Aurora Migration, Step by Step - AWS Online Tech Talks
Ā 
Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal
Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal
Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal
Ā 
Lecture17 ie321 dr_atifshahzad_js
Lecture17 ie321 dr_atifshahzad_jsLecture17 ie321 dr_atifshahzad_js
Lecture17 ie321 dr_atifshahzad_js
Ā 
Dart programming language
Dart programming languageDart programming language
Dart programming language
Ā 
SAP ABAP Latest Interview Questions
SAP ABAP Latest  Interview Questions SAP ABAP Latest  Interview Questions
SAP ABAP Latest Interview Questions
Ā 
8. data types
8. data types8. data types
8. data types
Ā 
2015 01-17 Lambda Architecture with Apache Spark, NextML Conference
2015 01-17 Lambda Architecture with Apache Spark, NextML Conference2015 01-17 Lambda Architecture with Apache Spark, NextML Conference
2015 01-17 Lambda Architecture with Apache Spark, NextML Conference
Ā 
copa-ii.pptx
copa-ii.pptxcopa-ii.pptx
copa-ii.pptx
Ā 
Spark Performance Tuning .pdf
Spark Performance Tuning .pdfSpark Performance Tuning .pdf
Spark Performance Tuning .pdf
Ā 
A Java Implementer's Guide to Better Apache Spark Performance
A Java Implementer's Guide to Better Apache Spark PerformanceA Java Implementer's Guide to Better Apache Spark Performance
A Java Implementer's Guide to Better Apache Spark Performance
Ā 
Z abap coding_standards_v2_0_t
Z abap coding_standards_v2_0_tZ abap coding_standards_v2_0_t
Z abap coding_standards_v2_0_t
Ā 
Java script summary
Java script summaryJava script summary
Java script summary
Ā 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(ā˜Žļø+971_581248768%)**%*]'#abortion pills for sale in dubai@
Ā 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
Ā 

Recently uploaded (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
Ā 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
Ā 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Ā 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Ā 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
Ā 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
Ā 
šŸ¬ The future of MySQL is Postgres šŸ˜
šŸ¬  The future of MySQL is Postgres   šŸ˜šŸ¬  The future of MySQL is Postgres   šŸ˜
šŸ¬ The future of MySQL is Postgres šŸ˜
Ā 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
Ā 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
Ā 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
Ā 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Ā 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Ā 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Ā 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
Ā 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
Ā 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
Ā 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
Ā 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Ā 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Ā 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
Ā 

JavaScript for ABAP Programmers - 2/7 Data Types

  • 1. JavaScript for ABAP Programmers Data Types Chris Whealy / The RIG
  • 2. ABAP Strongly typed Syntax similar to COBOL Block Scope No equivalent concept OO using class based inheritance Imperative programming JavaScript Weakly typed Syntax derived from Java Lexical Scope Functions are 1st class citizens OO using referential inheritance Imperative or Functional programming
  • 3. Strongly Typed vs. Weakly Typed Languages There are two schools of thought for determining how data should be stored in variables: ā€¢ ABAP uses Strong (or Static) Typing Apart from field symbols, all ABAP variables must have their data type defined at declaration time Ā© 2013 SAP AG. All rights reserved. 3
  • 4. Strongly Typed vs. Weakly Typed Languages There are two schools of thought for determining how data should be stored in variables: ā€¢ ABAP uses Strong (or Static) Typing ā€¢ JavaScript uses Weak (or Dynamic) Typing Apart from field symbols, all ABAP variables A variable takes on the data type of whatever must have their data type defined at declaration value it currently holds time Ā© 2013 SAP AG. All rights reserved. 4
  • 5. Strongly Typed vs. Weakly Typed Languages There are two schools of thought for determining how data should be stored in variables: ā€¢ ABAP uses Strong (or Static) Typing ā€¢ JavaScript uses Weak (or Dynamic) Typing Apart from field symbols, all ABAP variables A variable takes on the data type of whatever must have their data type defined at declaration value it currently holds time ā€¢ Pros and Cons of Strong Typing + Data type errors can be trapped at compile time - Rigid type systems reduce language flexibility Ā© 2013 SAP AG. All rights reserved. 5
  • 6. Strongly Typed vs. Weakly Typed Languages There are two schools of thought for determining how data should be stored in variables: ā€¢ ABAP uses Strong (or Static) Typing ā€¢ JavaScript uses Weak (or Dynamic) Typing Apart from field symbols, all ABAP variables A variable takes on the data type of whatever must have their data type defined at declaration value it currently holds time ā€¢ Pros and Cons of Strong Typing ā€¢ Pros and Cons of Weak Typing + Data type errors can be trapped at compile time - Rigid type systems reduce language flexibility - Data type errors can only be trapped at runtime + Highly flexible type system allows for a dynamic style of coding Ā© 2013 SAP AG. All rights reserved. 6
  • 7. Strongly Typed vs. Weakly Typed Languages There are two schools of thought for determining how data should be stored in variables: ā€¢ ABAP uses Strong (or Static) Typing ā€¢ JavaScript uses Weak (or Dynamic) Typing Apart from field symbols, all ABAP variables A variable takes on the data type of whatever must have their data type defined at declaration value it currently holds time ā€¢ Pros and Cons of Strong Typing ā€¢ Pros and Cons of Weak Typing + Data type errors can be trapped at compile time - Rigid type systems reduce language flexibility - Data type errors can only be trapped at runtime + Highly flexible type system allows for a dynamic style of coding Compiled languages (E.G. ABAP, Java, C) tend to use strong typing, whereas interpreted scripting languages (E.G. JavaScript, Ruby, Python) tend to use weak typing. Ā© 2013 SAP AG. All rights reserved. 7
  • 8. JavaScript Data Types: Overview In JavaScript, there are only 6 data types. At any one time the value of a variable belongs to one and only one of the following data types. Data Type This value of this variableā€¦ Null Is explicitly defined as having no value Undefined Is indeterminate Boolean Is either true or false String Is an immutable collection of zero or more Unicode characters Number Can be used in mathematical operations Object Is an unordered collection of name/value pairs Ā© 2013 SAP AG. All rights reserved. 8
  • 9. JavaScript Data Types 1/3 In the coding, the data types are specified as follows: // -----------------------------------------------------------------------------------------------// Special null; // Indicates an explicit non-value undefined; // Indicates an indeterminate value (E.G. a variable is declared but not initialised) Ā© 2013 SAP AG. All rights reserved. 9
  • 10. JavaScript Data Types 1/3 In the coding, the data types are specified as follows: // -----------------------------------------------------------------------------------------------// Special null; // Indicates an explicit non-value undefined; // Indicates an indeterminate value (E.G. a variable is declared but not initialised) // -----------------------------------------------------------------------------------------------// Boolean true; false; Ā© 2013 SAP AG. All rights reserved. 10
  • 11. JavaScript Data Types 1/3 In the coding, the data types are specified as follows: // -----------------------------------------------------------------------------------------------// Special null; // Indicates an explicit non-value undefined; // Indicates an indeterminate value (E.G. a variable is declared but not initialised) // -----------------------------------------------------------------------------------------------// Boolean true; false; // -----------------------------------------------------------------------------------------------// String ā€“ contains zero or more Unicode characters 'Bazinga!'; // Can be delimited by either single quotes ""; // Or double quotes Ā© 2013 SAP AG. All rights reserved. 11
  • 12. JavaScript Data Types 2/3 In the coding, the data types are specified as follows: // -----------------------------------------------------------------------------------------------// Number 3.1415926; // Stored as 64-bit floating point number 1; // Be careful, this is stored as floating point value, not an integer! Ā© 2013 SAP AG. All rights reserved. 12
  • 13. JavaScript Data Types 2/3 In the coding, the data types are specified as follows: // -----------------------------------------------------------------------------------------------// Number 3.1415926; // Stored as 64-bit floating point number 1; // Be careful, this is stored as floating point value, not an integer! // Warning! All the usual problems associated with trying to represent decimal values in binary // floating point format still apply in JavaScript! var result = 0.1 + 0.2; result; // ļƒ  0.30000000000000004, not 0.3 (Decimal 0.1 has no exact binary equivalent) Ā© 2013 SAP AG. All rights reserved. 13
  • 14. JavaScript Data Types 2/3 In the coding, the data types are specified as follows: // -----------------------------------------------------------------------------------------------// Number 3.1415926; // Stored as 64-bit floating point number 1; // Be careful, this is stored as floating point value, not an integer! // Warning! All the usual problems associated with trying to represent decimal values in binary // floating point format still apply in JavaScript! var result = 0.1 + 0.2; result; // ļƒ  0.30000000000000004, not 0.3 (Decimal 0.1 has no exact binary equivalent) // Special numerical values that could be returned in the event of illegal mathematical operations // (These values are actually stored as properties of the Global Object) NaN; // 'Not a Number' E.G. 1/'cat' ļƒ  NaN Infinity; // The result of division by zero Ā© 2013 SAP AG. All rights reserved. 14
  • 15. JavaScript Data Types 3/3 In addition to the basic data type of Object, JavaScript provides several built-in objects that behave as if they were composite data types. E.G. Array, Date, Function, Math and RegEx etc. // -----------------------------------------------------------------------------------------------// Object. Zero or more unordered name:value pairs of any data type delimited by curly braces { pet1: 'cat', pet2: 'dog' }; Ā© 2013 SAP AG. All rights reserved. 15
  • 16. JavaScript Data Types 3/3 In addition to the basic data type of Object, JavaScript provides several built-in objects that behave as if they were composite data types. E.G. Array, Date, Function, Math and RegEx etc. // -----------------------------------------------------------------------------------------------// Object. Zero or more unordered name:value pairs of any data type delimited by curly braces { pet1: 'cat', pet2: 'dog' }; // Array object. Zero or more values of any data type accessed by a numerical, 0 based index [1,2,3,4,5]; Ā© 2013 SAP AG. All rights reserved. 16
  • 17. JavaScript Data Types 3/3 In addition to the basic data type of Object, JavaScript provides several built-in objects that behave as if they were composite data types. E.G. Array, Date, Function, Math and RegEx etc. // -----------------------------------------------------------------------------------------------// Object. Zero or more unordered name:value pairs of any data type delimited by curly braces { pet1: 'cat', pet2: 'dog' }; // Array object. Zero or more values of any data type accessed by a numerical, 0 based index [1,2,3,4,5]; // Function object. A special object that has both properties and executable content function() { /* statements */ } Ā© 2013 SAP AG. All rights reserved. 17
  • 18. JavaScript Data Types 3/3 In addition to the basic data type of Object, JavaScript provides several built-in objects that behave as if they were composite data types. E.G. Array, Date, Function, Math and RegEx etc. // -----------------------------------------------------------------------------------------------// Object. Zero or more unordered name:value pairs of any data type delimited by curly braces { pet1: 'cat', pet2: 'dog' }; // Array object. Zero or more values of any data type accessed by a numerical, 0 based index [1,2,3,4,5]; // Function object. A special object that has both properties and executable content function() { /* statements */ } // Math object. Contains many useful mathematical functions and constants Math.PI; // ļƒ  3.141592653589793 Ā© 2013 SAP AG. All rights reserved. 18
  • 19. JavaScript Data Types 3/3 In addition to the basic data type of Object, JavaScript provides several built-in objects that behave as if they were composite data types. E.G. Array, Date, Function, Math and RegEx etc. // -----------------------------------------------------------------------------------------------// Object. Zero or more unordered name:value pairs of any data type delimited by curly braces { pet1: 'cat', pet2: 'dog' }; // Array object. Zero or more values of any data type accessed by a numerical, 0 based index [1,2,3,4,5]; // Function object. A special object that has both properties and executable content function() { /* statements */ } // Math object. Contains many useful mathematical functions and constants Math.PI; // ļƒ  3.141592653589793 // Regular Expression Object. A tool for specifying and extracting patterns of text within a string /^(?:([A-Za-z]+):)?(/{0,3})([0-9.-A-Za-z]+)(?::(d+))?(?:/([^?#]*))?(?:?([^#]*))?(?:#(.*))?$/; Ā© 2013 SAP AG. All rights reserved. 19
  • 20. JavaScript Data Types 3/3 In addition to the basic data type of Object, JavaScript provides several built-in objects that behave as if they were composite data types. E.G. Array, Date, Function, Math and RegEx etc. // -----------------------------------------------------------------------------------------------// Object. Zero or more unordered name:value pairs of any data type delimited by curly braces { pet1: 'cat', pet2: 'dog' }; // Array object. Zero or more values of any data type accessed by a numerical, 0 based index [1,2,3,4,5]; // Function object. A special object that has both properties and executable content function() { /* statements */ } // Math object. Contains many useful mathematical functions and constants Math.PI; // ļƒ  3.141592653589793 // Regular Expression Object. A tool for specifying and extracting patterns of text within a string // Regular expressions are sometimes confused with Egyptian hieroglyphics... :-) Ā© 2013 SAP AG. All rights reserved. 20
  • 21. Variables and Data Types In weakly typed languages such as JavaScript, there is no concept of declaring that a variable should hold data of a particular type. The data type of a variable is determined simply by the value it currently holds. // A weakly typed language means that data types are determined // dynamically at runtime, not statically at design time var whoAmI = 'Hello world'; Ā© 2013 SAP AG. All rights reserved. // Variable 'whoAmI' is both declared & assigned a string value 21
  • 22. Variables and Data Types In weakly typed languages such as JavaScript, there is no concept of declaring that a variable should hold data of a particular type. The data type of a variable is determined simply by the value it currently holds. // A weakly typed language means that data types are determined // dynamically at runtime, not statically at design time var whoAmI = 'Hello world'; // Variable 'whoAmI' is both declared & assigned a string value whoAmI = 1.61792; whoAmI = [1,2,3,4,5]; // Now it's a number // Now it's an array Ā© 2013 SAP AG. All rights reserved. 22
  • 23. Variables and Data Types In weakly typed languages such as JavaScript, there is no concept of declaring that a variable should hold data of a particular type. The data type of a variable is determined simply by the value it currently holds. // A weakly typed language means that data types are determined // dynamically at runtime, not statically at design time var whoAmI = 'Hello world'; // Variable 'whoAmI' is both declared & assigned a string value whoAmI = 1.61792; whoAmI = [1,2,3,4,5]; // Now it's a number // Now it's an array whoAmI = true; // Now it's a Boolean Ā© 2013 SAP AG. All rights reserved. 23
  • 24. Variables and Data Types In weakly typed languages such as JavaScript, there is no concept of declaring that a variable should hold data of a particular type. The data type of a variable is determined simply by the value it currently holds. // A weakly typed language means that data types are determined // dynamically at runtime, not statically at design time var whoAmI = 'Hello world'; // Variable 'whoAmI' is both declared & assigned a string value whoAmI = 1.61792; whoAmI = [1,2,3,4,5]; // Now it's a number // Now it's an array whoAmI = true; // Now it's a Boolean whoAmI = { // Now it's an object someProperty: 'Hello world' } Ā© 2013 SAP AG. All rights reserved. 24
  • 25. Variables and Data Types In weakly typed languages such as JavaScript, there is no concept of declaring that a variable should hold data of a particular type. The data type of a variable is determined simply by the value it currently holds. // A weakly typed language means that data types are determined // dynamically at runtime, not statically at design time var whoAmI = 'Hello world'; // Variable 'whoAmI' is both declared & assigned a string value whoAmI = 1.61792; whoAmI = [1,2,3,4,5]; // Now it's a number // Now it's an array whoAmI = true; // Now it's a Boolean whoAmI = { // Now it's an object someProperty: 'Hello world' } whoAmI = function() { }; Ā© 2013 SAP AG. All rights reserved. // Now it's a...you get the idea 25