In addition to the deprecation MattDMo pointed out here (and Nick in the comments), one small point:
Your two examples aren't quite equivalent. The precise equivalent of <!-- language: lang-js -->
with code fences is ```lang-js
(with the lang-
prefix). ```js
says "use the default formatter for the javascript tag" (because js
is an alias for javascript
), but <!-- language: lang-js -->
tells the site explicitly to format the code as JavaScript, without referring to the tag. It doesn't matter for JavaScript, but it does for some other tags, like typescript.
Details:
The token following the ```
in code fences is a tag identifier unless you have a lang-
prefix on it. It tells the site to use the default formatting for that tag, it doesn't refer to a specific language directly. To do that, use the lang-
prefix.
It matters for some tags, like typescript, because the default formatting for typescript posts is JavaScript, not TypeScript (at least for now). So if you do this:
```typescript
codeHere();
```
you'll get JavaScript formatting. This gives you TypeScript formatting:
```lang-typescript
codeHere();
```
It can matter, particularly with function overloads. Here's what a ```typescript
block looks like on SO (an image because the tag marker doesn't work on MSO):
Here's a ```lang-typescript
block:
function exampleOverload(a: number): number;
function exampleOverload(a: number[]): number[];
function exampleOverload(a: number | number[]): number | number[] {
if (Array.isArray(a)) {
return a.map(v => v * 2);
}
return a * 2;
}
Edits like those should be rejected...
But How to reject a code edit if it is approved before I even get a chance to have a look at it?<!-- lang-js -->
should not be used as that form of language declaration has been depracated,```javascript
should be preferred, although isn't mandated<!-- language: whatever -->
is deprecated and will be removed eventually. meta.stackexchange.com/questions/348746/…indented blocks
is deprecated and using it faces the risk of breaking the day SO decides to stop supporting it