sytax
This commit is contained in:
parent
eaf8456c6b
commit
1647746ddb
@ -1,2 +1,2 @@
|
||||
const message: string = 'Hello, World!';
|
||||
console.log(message);
|
||||
const helloworld: string = 'Hello, World!';
|
||||
console.log(helloworld);
|
||||
|
||||
11
src/02-syntax/tsconfig.json
Normal file
11
src/02-syntax/tsconfig.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2016",
|
||||
"module": "commonjs",
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"noImplicitAny": true
|
||||
}
|
||||
}
|
||||
4
src/02-syntax/typinferenz.ts
Normal file
4
src/02-syntax/typinferenz.ts
Normal file
@ -0,0 +1,4 @@
|
||||
let inferredCount = 100;
|
||||
let inferredMessage = 'Automatic detection';
|
||||
|
||||
// inferredMessage = 43;
|
||||
41
src/02-syntax/typsystem.ts
Normal file
41
src/02-syntax/typsystem.ts
Normal file
@ -0,0 +1,41 @@
|
||||
// const name: string = 'John';
|
||||
// const age: number = 30;
|
||||
// const isActive: boolean = true;
|
||||
const message = 'World';
|
||||
|
||||
const total: number = 10 + 20;
|
||||
const greeting: string = `Hello, ${message}!`;
|
||||
const isActive: boolean = total > 20;
|
||||
|
||||
let unknownValue: unknown = { message: 'Can be anything' };
|
||||
let anyValue: any = { count: '42' };
|
||||
|
||||
let nullableValue: null = null;
|
||||
let undefinedValue: undefined = undefined;
|
||||
let mixedType: number | string = 'flexible type';
|
||||
mixedType = 100;
|
||||
// mixedType = true;
|
||||
|
||||
// console.log(unknownValue)
|
||||
|
||||
let valueAny: any;
|
||||
|
||||
// value = 42;
|
||||
// value = true;
|
||||
// value = 'Hello';
|
||||
|
||||
// let numberValue: number = value;
|
||||
// console.log(numberValue * 2);
|
||||
|
||||
let value: unknown;
|
||||
|
||||
value = true;
|
||||
value = 'Hello';
|
||||
value = 42;
|
||||
|
||||
if (typeof value === 'number') {
|
||||
let numberValue: number = value;
|
||||
console.log(numberValue * 2);
|
||||
} else {
|
||||
console.log('value ist keine number');
|
||||
}
|
||||
47
src/02-syntax/variablen.ts
Normal file
47
src/02-syntax/variablen.ts
Normal file
@ -0,0 +1,47 @@
|
||||
// const name: string = 'John';
|
||||
// const age: number = 30;
|
||||
// const isActive: boolean = true;
|
||||
|
||||
const user = {
|
||||
name: 'John',
|
||||
};
|
||||
|
||||
console.log(age, isActive);
|
||||
|
||||
// name = "Alex";
|
||||
let city = 'Berlin';
|
||||
city = 'Frankfurt';
|
||||
|
||||
var address = {
|
||||
city: 'Berlin',
|
||||
};
|
||||
|
||||
function greet(name: string): string {
|
||||
return `Hello, ${name}`; // "Hello " + name
|
||||
}
|
||||
|
||||
console.log(greet('John'));
|
||||
|
||||
const zahl: number = 10;
|
||||
|
||||
if (zahl > 5) {
|
||||
console.log('Zahl ist größer als 5');
|
||||
} else if (zahl === 6) {
|
||||
console.log('Zahl ist 6');
|
||||
} else {
|
||||
console.log('Zahl ist kleiner');
|
||||
}
|
||||
|
||||
for (let i = 0; i < 3; i++) {
|
||||
console.log(`Durchlauf: ${i}`);
|
||||
}
|
||||
|
||||
function testVar() {
|
||||
for (var i = 0; i < 3; i++) {
|
||||
console.log(`i: ${i}`);
|
||||
}
|
||||
|
||||
console.log(i);
|
||||
}
|
||||
|
||||
console.log('test var: ', testVar());
|
||||
Loading…
x
Reference in New Issue
Block a user