JavaScript&TypeScript
W rain or shine w
-
Explore the eight common use techniques of JavaScript ES6: start the journey of modern programming In this blog post, we will explore eight common JavaScript ES6 use techniques to help you improve development efficiency and inject new vitality into your code. Through the introduction of this article, we have deeply explored eight common use techniques of JavaScript ES6, including deconstruction assignment, arrow function, template string, default parameter, expansion operator, modular import/export Promise and asynchronous/wait, as well as class and modular object-oriented. Modularization is an important concept in modern JavaScript development, ES6 provides modular import and export syntax, which allows us to better organize and manage code. However, this is just the tip of the iceberg of ES6, and there are more wonderful functions waiting for you to explore. original 2023-12-24 19:55:06 · 477 Reading· 0 Comments -
Advanced Type Conversion Technology in TypeScript: Mapping Type, Conditional Type and Type Inference Mapping type, conditional type and type inference are powerful tools provided by TypeScript, which can help you write safer and more efficient code. Whether you are dealing with object properties, selecting types based on conditions, or letting TypeScript automatically infer types, these technologies can make your code more flexible and maintainable. Mapping type is a very powerful technology in TypeScript, which allows us to create new types based on existing types. Type inference is an important function of TypeScript, which can automatically infer the type of variable according to the context. In this way, we choose different return types according to different types of conditions. In the above example, we defined a condition type. original 2023-12-19 19:12:07 · 463 Reading· 0 Comments -
Conversion between TS custom structure Long and number types The low order and high order are calculated according to their values. We use the unsigned shift right operator. In the above example, we first defined one., We directly combine low and high positions. Now, we can use the above function. Property to convert it to the corresponding. Combine low and high positions; And division to calculate the high order., We use the unsigned shift right operator. Next, we can write a general. The accuracy of the conversion is verified. We can implement the interface definition. Conversion function between types. First, we can write a general. Type and store the results in. Property is the corresponding Boolean value. Conversion between types. Finally, we printed them separately. original 2023-12-19 18:42:09 · 849 Reading· 1 Comments -
The Ultimate Guide to Type Conversion in TypeScript: From Zero to Deep In TypeScript, you can customize type conversion functions to handle specific type conversion logic. By writing custom functions, you can more flexibly control the details of type conversion and handle complex conversion requirements// Implement user-defined string to number logic In the above code, we defined a function named to convert a string to a number. Through user-defined functions, we can implement specific string to number conversion logic, such as using functions. original 2023-12-19 18:52:24 · 2405 Reading· 0 Comments -
TypeScript implements poker data decor, value acquisition and generation Then, we defined constants' LOGIC_MASK_COLOR 'and' LOGIC_MASK_VALUE 'to represent decor mask and numeric mask respectively` The GetCardColor 'function obtains the suit of a playing card through bitwise AND, that is, retains the value of the suit mask, and shifts the result to the right by 4 bits to get the value of the suit. Please note that it is assumed that the input 'cardData' parameter is a byte representing the playing card data, and the decor and numerical information have been processed according to the mask. Specifically, 'cardColor' is obtained by shifting the decor to the left by 4 bits and performing bitwise AND operation with the decor mask to ensure that the decor information is in the correct position. original 2023-12-14 14:03:24 · 130 Reading· 0 Comments -
Summary of common operators in TypeScript In TypeScript, the value of union type can be one of several types. The union type is usually associated with null or undefined. The null value merge operator is different from the logical or | | operator. The logical or will be on the left operand.) If the given value does not exist, it will be returned directly. Through the&operator, multiple types can be superimposed onto ⼀ and combined into ⼀ types. When we determine the type, we can use the suffix expression operator. The operator (|) is often used to separate each type when declaring union types., Returns the right operand, otherwise returns the left operand. Chain operators are similar, except that the right operand is returned when the reference is null (value). original 2023-09-24 12:20:35 · 276 Reading· 0 Comments -
Four Methods for TypeScript to Empty Arrays There are four ways to empty the array. original 2023-09-23 19:16:16 · 1439 Reading· 0 Comments -
30 minute quick TypeScript TypeScript should be familiar to people with OOP (Object Oriented Programming) background. In fact, the engineers who develop TypeScript are the Microsoft engineers who lead C # development, but the engineers carefully only borrowed the features that are meaningful to TypeScript, TypeScript In fact, it is more like JavaScript itself. From the dynamic and static aspects of programming languages, TypeScript is a static type programming language, JS is a dynamically typed programming language. Static types are type checked during compilation, and dynamic types are type checked during execution. The interface is structured. Any object with all the properties declared in the interface is compatible with the interface. original 2023-08-30 11:15:42 · 231 Reading· 0 Comments -
Brief description of JavaScript scope and variable usage rules In JavaScript, scopes are divided into two types: global scope and local scope. 1. Global scope: The global scope is the largest scope. Variables defined in the global scope can be used anywhere. When the browser page opens, it will automatically generate a global scope window for us. The scope will exist until the page is closed. The variables that we can access on the browser console are global scopes. original 2023-05-08 16:23:04 · 570 Reading· 0 Comments