Hey there,
If you're reading this particular post, I want to appreciate you specially by finding your way to my first technical writing blog post.
The Chinese proverb says "The journey of a thousand miles begun with a step".
Firstly, my name is Abel Emmanuel and I'm a software developer, open source contributor and advocate. I will like to wish my humble self happy birthday.
Today, being 20th December 2024, I started learning Typescript and technical writing. I've known Typescript for quite sometimes but I never saw the important, usefulness, rich features and how it'll help me write better code.
Ideally, I refused to learn Typescript earlier at the times I knew about it. I concluded there is no usefulness of learning Typescript since it has the same syntax and everything with JavaScript not until I got a job that required Typescript.
This is how I started learning Typescript properly, if not I have zeroed my mind on Typescript.
Today, I want to share the basic of Typescript and how important it is and how it can help you reduce the errors you write in your code.
JavaScript from birth is not a typed language like C, C , C#, Rust and other low-level programming language.
In typed languages, variables and values have a types.
This is what it means by typed-language using C programming language as a practical illustration.
For example in JavaScript to defined a variable:
In JavaScript, x can be reassign to a string value.
Compare with low-level language like C programming language that you have to let the variable aware of the value data type. For instance:
If you attempt to reassign variable x and y it throw an error. However, JavaScript is a loosely typed language which can cause plenty of bugs in your code.
To avoid this, you need a super-set of JavaScript called Typescript. Typescript is a static type checker that help check an error in a program before running the program.
Let get started
Install Typescript globally or locally into your project.
npm install -g typescript
Create a folder and name it typescript.
Right-click on the folder (typescript), open with visual studio code and create a file test.ts.
After you've done that, the next step is to start writing your typescript.
Inside your test.ts file copy and paste code inside the file and run it.
To run typescript file. Open your Command Line Interface (CLI) and tsc test.ts. The command will run the typescript file.
Note: If you do not install typescript you won't access tsc in the CLI.
After you run it, you'll notice that nothing spectacular happen in the CLI but however, you'll note a new file test.js in the folder.
Open the test.js file you will note the command you run will output everything in test.ts to test.js.
Let include types in our code. Let see how it look like in Javascript.
Run tsc test.ts. Nothing special happened.
However, assuming the function call meet() get a one argument like meet(7).
Typescript will indicate a an error.
Normally, in JavaScript world the code is cool but that isn't what we wanted. So even though it doesn't throw an error at runtime. Typescript has help us identify a problem before hand. This is the cooool part of typescript. It help you write a less buggy codes.
Let examine this code.
Note function meet(name: string, id: number), the additional :string and :number. this tell us that we are expecting a argument string and a number. If you do the otherwise your code will trigger an error.
Function return a type
We can allow our function to return a particular typed.
Object Typed
Other primitive typed Annotation.
In conclusion, Typescript is a typed language that help you write a better JavaScript and lesser bugs. Read more on Typescript Official website: Typescript.
Let me know if you find this post helpful and if there's a better way to improve I will be glad to learn from you. Thanks for reading my first post.
Follow me on Twitter where I share great content.
The above is the detailed content of How I start typescript.. For more information, please follow other related articles on the PHP Chinese website!

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Mac version
God-level code editing software (SublimeText3)