Skip to content

Data Type

WXS language currently has the following data types:

  • number :Number
  • string :String
  • boolean:Boolean value
  • object :Object
  • function :Function
  • array :Array
  • date :Date
  • regexp :Regular

number

Syntax

number includes two types of values: integer and decimal.

js
var a = 10;
var PI = 3.141592653589793;

Properties

  • constructor:Return string 'Number'

Method

  • toString;

  • toLocaleString;

  • valueOf;

  • toFixed;

  • toExponential;

  • toPrecision.

For the specific use of the above methods, please refer to the ES5 standard.

string

Syntax

String has two ways of writing:

js
'hello world';
"hello world";

Properties

  • constructor:Return string 'String'

  • length

For the specific meaning of properties except constructor, please refer to the ES5 standard.

Method

  • toString;
  • valueOf;
  • charAt;
  • charCodeAt;
  • concat;
  • indexOf;
  • lastIndexOf;
  • localeCompare;
  • match;
  • replace;
  • search;
  • slice;
  • split;
  • substring;
  • toLowerCase;
  • toLocaleLowerCase;
  • toUpperCase;
  • toLocaleUpperCase;
  • trim;
For the specific use of the above methods, please refer to the ES5 standard.

boolean

Syntax

Boolean has only two specific values: true and false

Properties

  • constructor:Returns the string 'Boolean'

Method

  • toString;
  • valueOf.
For the specific use of the above methods, please refer to the ES5 standard.

object

Syntax

object is an unordered key-value pair. The usage is as follows:

js
var o = {} // Generates a new empty object.

// Generates a new non-empty object.
o = {
 'string'  : 1,  //The object’s key can be a string.
 const_var : 2,  //The object’s key can also be an identifier that conforms to the variable definition rules.
 func      : {}, //The object’s value can be of any type.
};

//Object property read operation
console.log(1 === o['string']);
console.log(2 === o.const_var);

//Object property write operation
o['string']++;
o['string'] += 10;
o.const_var++;
o.const_var += 10;

//Object property read operation
console.log(12 === o['string']);
console.log(13 === o.const_var);

Properties

constructor:Returns the string 'Object'

js
console.log("Object" === {k:"1",v:"2"}.constructor)

Method

toString:Returns the string '[object Object]'

function

Syntax

Function supports the following definition methods:

js
//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.):

js
var a = function (x) {
  return function () { return x;}
}

var b = a(100);
console.log( 100 === b() );

arguments

The arguments keyword can be used in function. This keyword currently only supports the following properties:

  • length: The number of parameters passed to the function;
  • [index] The number of parameters passed to the function;
Sample code:
js
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.

Method

  • toString:Returns the string '[function Function]'.
Sample code:
js
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 definitions:

js
var a = [];      // Generates a new empty array.

a = [1,"2",{},function(){}];  // Generates a new non-empty array, with array elements of any type.

Properties

  • constructor:Return the string 'Array'

  • length.

For the specific meaning of properties except constructor, please refer to the ES5 standard.

Method

  • toString
  • concat
  • join
  • pop
  • push
  • reverse
  • shift
  • slice
  • sort
  • splice
  • unshift
  • indexOf
  • lastIndexOf
  • every
  • some
  • forEach
  • map
  • filter
  • reduce
  • reduceRight
For the specific use of the above methods, please refer to the ES5 standard.

date

Syntax

To generate a date object, you need to use the getDate function, which returns an object of the current time.

js
getDate()
getDate(milliseconds)
getDate(datestring)
getDate(year, month[, date[, hours[, minutes[, seconds[, milliseconds]]]]])
  • Parameter
    • milliseconds:The number of milliseconds calculated from January 1, 1970 00:00:00 UTC;
    • datestring:Date string, its format is: 'month day, year hours:minutes:seconds'.

Sample code:

js
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

constructorReturns the string 'Date'.

Method

  • toString;
  • toDateString;
  • toTimeString;
  • toLocaleString;
  • toLocaleDateString;
  • toLocaleTimeString;
  • valueOf;
  • getTime;
  • getFullYear;
  • getUTCFullYear;
  • getMonth;
  • getUTCMonth;
  • getDate;
  • getUTCDate;
  • getDay;
  • getUTCDay;
  • getHours;
  • getUTCHours;
  • getMinutes;
  • getUTCMinutes;
  • getSeconds;
  • getUTCSeconds;
  • getMilliseconds;
  • getUTCMilliseconds;
  • getTimezoneOffset;
  • setTime;
  • setMilliseconds;
  • setUTCMilliseconds
  • setSeconds;
  • setUTCSeconds;
  • setMinutes;
  • setUTCMinutes;
  • setHours;
  • setUTCHours;
  • setDate;
  • setUTCDate;
  • setUTCMonth;
  • setFullYear;
  • setUTCFullYear;
  • toUTCString;
  • toISOString;
  • toJSON;
For the specific use of the above methods, please refer to the ES5 standard.

regexp

Syntax

To generate a regexp object, you need to use the getRegExp function.

js
getRegExp(pattern[, flags])
  • Parameter:
    • pattern:Regular expression content
    • flags:Modifier. This field can only contain the following characters:
      • g: global
      • i: ignoreCase
      • m: multiline

Sample code:

js
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'
  • source
  • global
  • ignoreCase
  • multiline
  • lastIndex
For the specific meaning of properties except constructor, please refer to the ES5 standard.

Method

  • exec;
  • test;
  • toString.
For the specific use of the above methods, please refer to the ES5 standard.

Data type judgment

Constructor property

The constructor property can be used to judge the data type.

Sample code:

js
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

Use typeof to distinguish some data types.

Sample code:

js
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 );