From 99534d5d02fb258570d9efa96e3b95ffffe3ab57 Mon Sep 17 00:00:00 2001 From: PinkR1ver <3180102330@zju.edu.cn> Date: Wed, 27 Mar 2024 19:29:05 +0800 Subject: [PATCH] Add note --- .../coding_knowledge/coding_lang_MOC.md | 7 ++-- .../js/TypeScript_vs_JavaScript.md | 38 +++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 content/computer_sci/coding_knowledge/js/TypeScript_vs_JavaScript.md diff --git a/content/computer_sci/coding_knowledge/coding_lang_MOC.md b/content/computer_sci/coding_knowledge/coding_lang_MOC.md index 35f1d9c51..3d902a146 100644 --- a/content/computer_sci/coding_knowledge/coding_lang_MOC.md +++ b/content/computer_sci/coding_knowledge/coding_lang_MOC.md @@ -4,7 +4,7 @@ tags: - basic - coding-language - MOC -date: 2024-03-18 +date: 2024-03-27 --- # Python @@ -27,7 +27,8 @@ date: 2024-03-18 * [Plot UI components for MATLAB](computer_sci/coding_knowledge/matlab/uicontrol.md) -# JavaScript +# JavaScript & TypeScript -* +* [DOM](computer_sci/coding_knowledge/js/DOM.md) +* [TypeScript vs. JavaScript](computer_sci/coding_knowledge/js/TypeScript_vs_JavaScript.md) diff --git a/content/computer_sci/coding_knowledge/js/TypeScript_vs_JavaScript.md b/content/computer_sci/coding_knowledge/js/TypeScript_vs_JavaScript.md new file mode 100644 index 000000000..62bbe4d93 --- /dev/null +++ b/content/computer_sci/coding_knowledge/js/TypeScript_vs_JavaScript.md @@ -0,0 +1,38 @@ +--- +title: JavaScript vs. TypeScript +tags: + - coding-language + - typescript + - javascript + - web +date: 2024-03-27 +--- + + +**1. Typing:** + +- **TypeScript:** Statically typed. You need to explicitly define the data types of variables and functions. This helps catch errors early in the development process. +- **JavaScript:** Dynamically typed. Variables don't require explicit data type definition. This offers flexibility but can lead to runtime errors. + +**2. Features:** + +- **TypeScript:** Adds features like interfaces, classes, generics, and enums on top of JavaScript. These features improve code organization, readability, and maintainability for larger projects. +- **JavaScript:** Lacks these features but has a vast ecosystem of libraries that can provide similar functionalities. + +**3. Compilation:** + +- **TypeScript:** Needs to be compiled to JavaScript before running in a browser. This compilation step adds another step to the development process. +- **JavaScript:** Runs directly in the browser without any compilation needed. + +**4. Choosing Between TypeScript and JavaScript:** + +- **TypeScript:** Ideal for large-scale applications, projects requiring strong typing and better tooling support, and teams working collaboratively. +- **JavaScript:** Preferred for smaller projects, rapid prototyping, or when flexibility and faster turnaround time are priorities. + +| Feature | TypeScript | JavaScript | +| ----------- | ---------------------------------------------- | ----------------------------------------------- | +| Typing | Statically typed | Dynamically typed | +| Features | Includes classes, interfaces, generics, enums | Relies on libraries for similar functionalities | +| Compilation | Requires compilation to JavaScript | Runs directly in the browser | +| Use Cases | Large-scale applications, strong typing needed | Smaller projects, rapid prototyping | +| | | |