# Data Types
The FTS language currently supports the following data types:
number: Numeric valuestring: Stringboolean: Boolean valueobject: Objectfunction: Functionarray: Arraydate: Dateregexp: Regular expression
# number
# Syntax
number includes two types of values: integers and decimals.
var a = 10;
var PI = 3.141592653589793;
# Properties
constructor: Returns the string"Number".
# Methods
toStringtoLocaleStringvalueOftoFixedtoExponentialtoPrecision
For specific usage of the above methods, please refer to the
ES5standard
# string
# Syntax
string has two writing methods:
'hello world';
"hello world";
# Properties
constructor: Returns the string"String".length
For the specific meaning of properties other than
constructor, please refer to theES5standard
# Methods
toStringvalueOfcharAtcharCodeAtconcatindexOflastIndexOflocaleComparematchreplacesearchslicesplitsubstringtoLowerCasetoLocaleLowerCasetoUpperCasetoLocaleUpperCasetrim
For specific usage of the above methods, please refer to the
ES5standard
# boolean
# Syntax
Boolean values have only two specific values: true and false.
# Properties
constructor: Returns the string"Boolean".
# Methods
toStringvalueOf
For specific usage of the above methods, please refer to the
ES5standard
# object
# Syntax
object is an unordered key-value pair. Usage is as follows:
var o = {} // Create a new empty object
// Create a new non-empty object
o = {
'string' : 1, // The key of an object can be a string
const_var : 2, // The key of an object can also be an identifier that conforms to variable definition rules
func : {}, // The value of an object can be any type
};
// Read operation of object properties
console.log(1 === o['string']);
console.log(2 === o.const_var);
// Write operation of object properties
o['string']++;
o['string'] += 10;
o.const_var++;
o.const_var += 10;
// Read operation of object properties
console.log(12 === o['string']);
console.log(13 === o.const_var);
# Properties
constructor: Returns the string"Object".
console.log("Object" === {k:"1",v:"2"}.constructor)
# Methods
toString: Returns the string"[object Object]".
# function
# Syntax
function supports the following definition methods:
// Method 1
function a (x) {
return x;
}
// Method 2
var b = function (x) {
return x;
}
function also supports the following syntax (anonymous functions, closures, etc.):
var a = function (x) {
return function () { return x;}
}
var b = a(100);
console.log( 100 === b() );
# arguments
The arguments keyword can be used inside functions. This keyword currently only supports the following properties:
length: The number of arguments passed to the function.[index]: Theindexsubscript can be used to traverse each argument passed to the function.
# Example Code
var a = function(){
console.log(3 === arguments.length);
console.log(100 === arguments[0]);
console.log(200 === arguments[1]);
console.log(300 === arguments[2]);
};
a(100,200,300);
# Properties
constructor: Returns the string"Function".length: Returns the number of formal parameters of the function.
# Methods
toString: Returns the string"[function Function]".
# Example Code
var func = function (a,b,c) { }
console.log("Function" === func.constructor);
console.log(3 === func.length);
console.log("[function Function]" === func.toString());
# array
# Syntax
array supports the following definition methods:
var a = []; // Create a new empty array
a = [1,"2",{},function(){}]; // Create a new non-empty array, array elements can be any type
# Properties
constructor: Returns the string"Array".length
For the specific meaning of properties other than constructor, please refer to the
ES5standard.
# Methods
toStringconcatjoinpoppushreverseshiftslicesortspliceunshiftindexOflastIndexOfeverysomeforEachmapfilterreducereduceRight
For specific usage of the above methods, please refer to the
ES5standard.
# date
# Syntax
To create a date object, use the getDate function, which returns an object representing the current time.
getDate()
getDate(milliseconds)
getDate(datestring)
getDate(year, month[, date[, hours[, minutes[, seconds[, milliseconds]]]]])
# Parameters
milliseconds: The number of milliseconds since January 1, 1970, 00:00:00 UTC.datestring: Date string, the format is: "month day, year hours:minutes:seconds".
# Example Code
var date = getDate(); // Returns the current time object
date = getDate(1500000000000);
// Fri Jul 14 2017 10:40:00 GMT+0800 (China Standard Time)
date = getDate('2017-7-14');
// Fri Jul 14 2017 00:00:00 GMT+0800 (China Standard Time)
date = getDate(2017, 6, 14, 10, 40, 0, 0);
// Fri Jul 14 2017 10:40:00 GMT+0800 (China Standard Time)
# Properties
constructor: Returns the string"Date".
# Methods
toStringtoDateStringtoTimeStringtoLocaleStringtoLocaleDateStringtoLocaleTimeStringvalueOfgetTimegetFullYeargetUTCFullYeargetMonthgetUTCMonthgetDategetUTCDategetDaygetUTCDaygetHoursgetUTCHoursgetMinutesgetUTCMinutesgetSecondsgetUTCSecondsgetMillisecondsgetUTCMillisecondsgetTimezoneOffsetsetTimesetMillisecondssetUTCMillisecondssetSecondssetUTCSecondssetMinutessetUTCMinutessetHourssetUTCHourssetDatesetUTCDatesetMonthsetUTCMonthsetFullYearsetUTCFullYeartoUTCStringtoISOStringtoJSON
For specific usage of the above methods, please refer to the
ES5standard
# regexp
# Syntax
To create a regexp object, use the getRegExp function.
getRegExp(pattern[, flags])
- Parameters:
pattern: The content of the regular expression.flags: Modifiers. This field can only contain the following characters:g: globali: ignoreCasem: multiline.
# Example Code
var a = getRegExp("x", "img");
console.log("x" === a.source);
console.log(true === a.global);
console.log(true === a.ignoreCase);
console.log(true === a.multiline);
# Properties
constructor: Returns the string"RegExp".sourceglobalignoreCasemultilinelastIndex
For the specific meaning of properties other than constructor, please refer to the
ES5standard.
# Methods
exectesttoString
For specific usage of the above methods, please refer to the
ES5standard.
# Data Type Judgment
# constructor Property
Data type judgment can use the constructor property.
# Example Code
var number = 10;
console.log( "Number" === number.constructor );
var string = "str";
console.log( "String" === string.constructor );
var boolean = true;
console.log( "Boolean" === boolean.constructor );
var object = {};
console.log( "Object" === object.constructor );
var func = function(){};
console.log( "Function" === func.constructor );
var array = [];
console.log( "Array" === array.constructor );
var date = getDate();
console.log( "Date" === date.constructor );
var regexp = getRegExp();
console.log( "RegExp" === regexp.constructor );
# typeof
Using typeof can also distinguish some data types.
# Example Code
var number = 10;
var boolean = true;
var object = {};
var func = function(){};
var array = [];
var date = getDate();
var regexp = getRegExp();
console.log( 'number' === typeof number );
console.log( 'boolean' === typeof boolean );
console.log( 'object' === typeof object );
console.log( 'function' === typeof func );
console.log( 'object' === typeof array );
console.log( 'object' === typeof date );
console.log( 'object' === typeof regexp );
console.log( 'undefined' === typeof undefined );
console.log( 'object' === typeof null );