syntax-variables-and-data-types-slides
syntax-variables-and-data-types-slides
Data Types
David Tucker
CTO Consultant
@_davidtucker_ | davidtucker.net
Syntax
Syntax is a set of rules that defines how the collection of
characters and symbols should be structured within a
programming language.
index.js
console.log("Hello");
let sum = 2 + 3;
console.log(sum);
JavaScript Keywords
abstract default for new throw
arguments delete function null throws
await do goto package transient
boolean double if private true
break else implements protected try
byte enum import public typeof
case eval in return var
catch export instanceof short void
char extends int static volatile
class false interface super while
const final let switch with
continue finally long synchronized yield
debugger float native this
index.js
/**
* Joins the first and last names together.
*
* @param {string} firstName The first name
Documentation * @param {string} lastName The last name
and Configuration * @return {string} The full name
*/
function getFullName(firstName, lastName) {
return `${firstName} ${lastName}`;
};
Wikipedia
Data Types
Dynamic Typing
JavaScript is a dynamic language with dynamic types. Variables in
JavaScript are not directly associated with any particular value
type, and any variable can be assigned (and re-assigned) values
of all types.
Stack Heap
JavaScript Data Types
Primitive
// String
Wrapper Methods let name = "David";
let upperCaseName = name.toUpperCase(); // DAVID
Creating and Using Strings
Using Boolean Values
Storing Numeric Values
Number
The JavaScript Number type is a double-precision 64-bit binary
format IEEE 754 value, like double in Java or C#. This means it can
represent fractional values, but there are some limits to the stored
number's magnitude and precision.
Inheritance
index.js
class CalendarDay {
// private fields
#month;
#day;
#year;
//constructor
Creating a constructor(month, day, year) {
JavaScript Class this.month = month;
this.day = day;
this.year = year;
}
// public method
toString() {
return `${this.year}-${this.month+1}-${this.day}`;
}
}
index.js