0% found this document useful (0 votes)
22 views

Javascript For Abap Programmers: Chapter 2 - Data Types

Uploaded by

Sandeep
Copyright
© © All Rights Reserved
Available Formats
Download as PPSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Javascript For Abap Programmers: Chapter 2 - Data Types

Uploaded by

Sandeep
Copyright
© © All Rights Reserved
Available Formats
Download as PPSX, PDF, TXT or read online on Scribd
You are on page 1/ 26

JavaScript for ABAP Programmers

Chapter 2 - Data Types


Chris Whealy / Technology RIG
ABAP JavaScript
Data typing Strong Weak
Syntax Similar to COBOL Derived mainly from Java with some influence from C
Variable Scope Block scope Lexical (or function) scope
“Function” No concept of a function as a Functions are 1st class citizens.
Concept data object That is, a function is an object with “an executable part”
Inheritance Model Class based Referential (or Prototypical)
Programming Style Strictly Imperative Both Imperative and Functional
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

© 2015 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

© 2015 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

© 2015 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 - Data type errors can only be trapped at runtime
- Rigid type systems reduce language flexibility + Flexible type system allows for a highly dynamic
style of coding

© 2015 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 - Data type errors can only be trapped at runtime
- Rigid type systems reduce language flexibility + Flexible type system allows for a highly 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.

© 2015 SAP AG. All rights reserved. 7


JavaScript Data Types: Overview

In JavaScript, there are only 6 data types.


At any one time, a variable holds a value that belongs to one and only one of the following data types:

Data Type The value of this variable…


Null Is explicitly defined as having no value
Undefined Cannot be determined
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

© 2015 SAP AG. All rights reserved. 8


JavaScript Data Types 1/3

There are some reserved words for referencing the special data types:

// ------------------------------------------------------------------------------------------------
// Special
null; // Indicates an explicit non-value
undefined; // Indicates an indeterminate value (E.G. a variable is declared but not initialised)

© 2015 SAP AG. All rights reserved. 9


JavaScript Data Types 1/3

There are some reserved words for referencing the special data types and the Boolean data types:

// ------------------------------------------------------------------------------------------------
// Special
null; // Indicates an explicit non-value
undefined; // Indicates an indeterminate value (E.G. a variable is declared but not initialised)

// ------------------------------------------------------------------------------------------------
// Boolean
true;
false;

© 2015 SAP AG. All rights reserved. 10


JavaScript Data Types 1/3

There are some reserved words for referencing the special data types and the Boolean data types.
After that, variables simply take on the value of whatever data they have been assigned.
// ------------------------------------------------------------------------------------------------
// 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

© 2015 SAP AG. All rights reserved. 11


JavaScript Data Types 2/3

Numbers can be specified in either decimal or integer notation.

// ------------------------------------------------------------------------------------------------
// Number
3.1415926; // Stored as 64-bit floating point number
1; // Be careful, this is stored as floating point value, not an integer!

© 2015 SAP AG. All rights reserved. 12


JavaScript Data Types 2/3

But be careful! All the usual problems associated with floating point numbers still exist in JavaScript.

// ------------------------------------------------------------------------------------------------
// 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)

© 2015 SAP AG. All rights reserved. 13


JavaScript Data Types 2/3

There are two special values for handling the results of an illegal mathematical operation.

// ------------------------------------------------------------------------------------------------
// 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

© 2015 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' };

© 2015 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];

© 2015 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 */ }

© 2015 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

© 2015 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+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/;

© 2015 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... :-)

© 2015 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
any 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

© 2015 SAP AG. All rights reserved. 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
any 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; // Now it's a number


whoAmI = [1,2,3,4,5]; // Now it's an array

© 2015 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
any 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; // Now it's a number


whoAmI = [1,2,3,4,5]; // Now it's an array

whoAmI = true; // Now it's a Boolean

© 2015 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
any 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; // Now it's a number


whoAmI = [1,2,3,4,5]; // Now it's an array

whoAmI = true; // Now it's a Boolean

whoAmI = { // Now it's an object


someProperty: 'Hello world'
}

© 2015 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
any 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; // Now it's a number


whoAmI = [1,2,3,4,5]; // Now it's an array

whoAmI = true; // Now it's a Boolean

whoAmI = { // Now it's an object


someProperty: 'Hello world'
}

whoAmI = function() { }; // Now it's a...you get the idea

© 2015 SAP AG. All rights reserved. 25


© 2015 SAP AG. All rights reserved.

No part of this publication may be reproduced or transmitted in any form or for any purpose without the express Google App Engine, Google Apps, Google Checkout, Google Data API, Google Maps, Google Mobile Ads,
permission of SAP AG. The information contained herein may be changed without prior notice. Google Mobile Updater, Google Mobile, Google Store, Google Sync, Google Updater, Google Voice,
Google Mail, Gmail, YouTube, Dalvik and Android are trademarks or registered trademarks of Google Inc.
Some software products marketed by SAP AG and its distributors contain proprietary software components of
other software vendors. INTERMEC is a registered trademark of Intermec Technologies Corporation.
Microsoft, Windows, Excel, Outlook, PowerPoint, Silverlight, and Visual Studio are registered trademarks of Wi-Fi is a registered trademark of Wi-Fi Alliance.
Microsoft Corporation.
Bluetooth is a registered trademark of Bluetooth SIG Inc.
IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System
Motorola is a registered trademark of Motorola Trademark Holdings LLC.
z10, z10, z/VM, z/OS, OS/390, zEnterprise, PowerVM, Power Architecture, Power Systems, POWER7,
POWER6+, POWER6, POWER, PowerHA, pureScale, PowerPC, BladeCenter, System Storage, Storwize, Computop is a registered trademark of Computop Wirtschaftsinformatik GmbH.
XIV, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, AIX, Intelligent Miner, WebSphere,
Tivoli, Informix, and Smarter Planet are trademarks or registered trademarks of IBM Corporation. SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP BusinessObjects Explorer, StreamWork,
SAP HANA, and other SAP products and services mentioned herein as well as their respective logos are
Linux is the registered trademark of Linus Torvalds in the United States and other countries. trademarks or registered trademarks of SAP AG in Germany and other countries.
Adobe, the Adobe logo, Acrobat, PostScript, and Reader are trademarks or registered trademarks of Adobe Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web
Systems Incorporated in the United States and other countries. Intelligence, Xcelsius, and other Business Objects products and services mentioned herein as well as their
respective logos are trademarks or registered trademarks of Business Objects Software Ltd. Business Objects
Oracle and Java are registered trademarks of Oracle and its affiliates.
is an SAP company.
UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group.
Sybase and Adaptive Server, iAnywhere, Sybase 365, SQL Anywhere, and other Sybase products and services
Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or mentioned herein as well as their respective logos are trademarks or registered trademarks of Sybase Inc.
registered trademarks of Citrix Systems Inc. Sybase is an SAP company.
HTML, XML, XHTML, and W3C are trademarks or registered trademarks of W3C®, World Wide Web Crossgate, m@gic EDDY, B2B 360°, and B2B 360° Services are registered trademarks of Crossgate AG
Consortium, Massachusetts Institute of Technology. in Germany and other countries. Crossgate is an SAP company.
Apple, App Store, iBooks, iPad, iPhone, iPhoto, iPod, iTunes, Multi-Touch, Objective-C, Retina, Safari, Siri, All other product and service names mentioned are the trademarks of their respective companies. Data
and Xcode are trademarks or registered trademarks of Apple Inc. contained in this document serves informational purposes only. National product specifications may vary.
IOS is a registered trademark of Cisco Systems Inc. The information in this document is proprietary to SAP. No part of this document may be reproduced, copied,
or transmitted in any form or for any purpose without the express prior written permission of SAP AG.
RIM, BlackBerry, BBM, BlackBerry Curve, BlackBerry Bold, BlackBerry Pearl, BlackBerry Torch, BlackBerry
Storm, BlackBerry Storm2, BlackBerry PlayBook, and BlackBerry App World are trademarks or registered
trademarks of Research in Motion Limited.

© 2015 SAP AG. All rights reserved. 26

You might also like