mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-26 00:26:29 +08:00
added Typescript and Javascript examples in data_and_memory.md
This commit is contained in:
parent
7a53f1d082
commit
eb3f1b61a6
1 changed files with 8 additions and 2 deletions
|
@ -84,13 +84,19 @@ comments: true
|
||||||
=== "JavaScript"
|
=== "JavaScript"
|
||||||
|
|
||||||
```js title=""
|
```js title=""
|
||||||
|
// JavaScript 的数组可以自由存储各种基本数据类型和对象
|
||||||
|
// JavaScript 的基本数据类型中只有数字, 没有浮点数, 这里使用0.1作为示例
|
||||||
|
const array = [0, 0.1, 'a', false]
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "TypeScript"
|
=== "TypeScript"
|
||||||
|
|
||||||
```typescript title=""
|
```typescript title=""
|
||||||
|
// TypeScript 可以定义 JavaScript 数组的类型
|
||||||
|
const numbers: number = new Array(5).fill(0);
|
||||||
|
const decimals: number = new Array(5).fill(0.1);
|
||||||
|
const characters: string = new Array(5).fill('a');
|
||||||
|
const booleans: boolean = new Array(5).fill(true);
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "C"
|
=== "C"
|
||||||
|
|
Loading…
Reference in a new issue