TIL about the ?? operator

This commit is contained in:
Ben Edgington
2025-06-07 15:15:54 +01:00
parent 31f74a43e7
commit d33f1aed88
2 changed files with 3 additions and 5 deletions

View File

@@ -49,10 +49,8 @@ const defaultHeadings = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
const defaultExclude = undefined;
export default function (options) {
const headings =
options?.headings !== undefined ? options.headings : defaultHeadings;
const exclude =
options?.exclude !== undefined ? options.exclude : defaultExclude;
const headings = options?.headings ?? defaultHeadings;
const exclude = options?.exclude ?? defaultExclude;
return {
name: 'myAutoLinkHeadings',
hooks: {

View File

@@ -70,7 +70,7 @@ function getChunks(tree, chunkTypes, exclude) {
label: type.label,
id: id,
text: text,
weight: type.weight === undefined ? 1 : type.weight,
weight: type.weight ?? 1,
});
}
return SKIP;