What does idiomatic javascript really mean ?
What is valid/idiomatic javascript
In JavaScript, idiomatic code is code that follows the established conventions and best practices for the language. It is code that is easy to read, understand, and maintain for other developers who are familiar with JavaScript.
There are many things that can make JavaScript code idiomatic, but some common characteristics include:
- Using descriptive, meaningful variable names
- Using white space and indentation to improve readability
- Using appropriate control structures (e.g., using for loops to iterate over arrays, using switch statements to handle multiple cases)
- Properly handling errors and exceptions
- Using modern syntax and features, such as arrow functions and the spread operator
- Avoiding the use of global variables
Of course, what is considered idiomatic can vary somewhat depending on the context and the preferences of the developer or development team. However, following established best practices is generally a good way to write code that is clear, concise, and maintainable.
What are the aspects of typescript which are not idiomatic to js developers ?
TypeScript is a programming language that is a super set of JavaScript, so all JavaScript code is also valid TypeScript code. However, TypeScript introduces some additional features that may be unfamiliar to developers who only have experience with JavaScript.
Some aspects of TypeScript that may not be immediately familiar to JavaScript developers include:
-
Type annotations: TypeScript allows developers to specify the types of variables, function arguments, and return values using type annotations. This can be unfamiliar to developers who are used to JavaScript's dynamic typing system.
-
Interfaces: TypeScript allows developers to define interfaces, which are sets of related properties and methods that a class or object can implement. This can be a useful tool for defining contracts in your code, but may not be familiar to developers who are used to JavaScript's prototype-based inheritance model.
-
Classes: TypeScript introduces a class-based object-oriented programming model, which may be unfamiliar to developers who are used to JavaScript's prototype-based inheritance model.
-
Generics: TypeScript allows developers to create generic types and functions, which can be used to create more flexible and reusable code. This can be a powerful feature, but may require some learning for developers who are not familiar with generics.
Overall, while TypeScript builds on top of JavaScript and shares many of the same features, it does introduce some additional concepts that may be unfamiliar to JavaScript developers. However, with some learning and practice, developers should be able to become proficient in using these features in their TypeScript code.