The boolean literals are true
and false
.
let isDone = true
let singleQuote = 'John'
let doubleQuote = "Jane"
🚧 kaoscript will support multilines strings.
Numbers are floating point values like in JavaScript but with more possible literals.
_
can be used to make to number more readable.
An unit can also be added at the end of the number.
🚧 kaoscript will improve its support of traditional number systems to avoid the caveats of JavaScript numbers.
let int = 6
let time = 10_000_ms
let float = 3.14
let group = 123_456.789_012
let scientific = -7.2e+3 //-7200
let dot = .789_012
let dotScientific = .1E4 // 1000
let binary = 0b1010
let binary = 0b1010010101
kaoscript supports hexadecimal floating literals introduced in C99 or C++ 17
let hex = 0xf00d
let group = 0x1234_5678
let float1 = 0x10.1p0 // 16.0625
let float2 = 0x1.2p3 // 9
let float3 = 0x3.14p0 // 3.078125
let float4 = 0xa.bp10 // 10944
Octal literals are extented with same floating literal as the hexadecimal literals.
let octal = 0o744
Radix literals allow you to define you own radix.
let radix36 = 36rNFfdH45
let radix7 = 7r66.6
if x == NaN {
}
if y == Infinity {
}
let array = [1, 2, 3]
You can also define an array with a range.
let a = [1..5]
// 1, 2, 3, 4, 5
let b = [1..<5]
// 1, 2, 3, 4
let c = [1<..5]
// 2, 3, 4, 5
let d = [1<..<5]
// 2, 3, 4
let e = [1..6..2]
// 1, 3, 5
let f = [1<..<6..2]
// 3, 5
let g = [5..1]
// 5, 4, 3, 2, 1
let h = [5..1..2]
// 5, 3, 1
let i = [1..2..0.3]
// 1.0, 1.3, 1.6, 1.9
let i = [1..2..0.2]
// 1.0, 1.2, 1.4, 1.6, 1.8, 2.0
let min = 1
let max = 5
let a = [min..max]
// 1, 2, 3, 4, 5
let foo = {}
// {}
let bar = {
bar: 'hello',
'qux': 'world'
}
// {"bar": "hello", "qux": "world"}
let x = 1
let y = 2
let z = 3
let foo1 = {x, y, z}
// {"x": "1", "y": "2", "z": "3"}
let foo2 = {
x,
y,
z
}
// {"x": "1", "y": "2", "z": "3"}
let foo3 = {
x
y
z
}
// {"x": "1", "y": "2", "z": "3"}
let bar = 'x'
let foo1 = {
[bar]: 42
}
// {"x": 42}
let foo2 = {
`\(bar)`: 42
}
// {"x": 42}
🚧
Object
in kaoscript might evolve into trueDictionary
. With no default methods added to them.
kaoscript uses the RegExp class from JavaScript.
let r = /foobar/gim
let n = null
let message = 'Hello!'
let name = 'John'
let template = `\(message)\nIt's nice to meet you, \(name).`
// Hello! \nIt's nice to meet you, John.
let person = 'Mike'
let age = 28
func myTag(strings, personExp, ageExp) {
const str0 = strings[0]
const str1 = strings[1]
let ageStr
if ageExp > 99 {
ageStr = 'centenarian'
}
else {
ageStr = 'youngster'
}
return `\(str0)\(personExp)\(str1)\(ageStr)`
}
const text = myTag`That \( person ) is a \( age )`
// text: That Mike is a youngster