diff --git a/packages/govuk-frontend/src/govuk/all.mjs b/packages/govuk-frontend/src/govuk/all.mjs index eb322df5d3..86bfb13f74 100644 --- a/packages/govuk-frontend/src/govuk/all.mjs +++ b/packages/govuk-frontend/src/govuk/all.mjs @@ -48,7 +48,7 @@ function initAll(config) { // Allow the user to initialise GOV.UK Frontend in only certain sections of the page // Defaults to the entire document if nothing is set. - const $scope = config.scope || document + const $scope = config.scope ?? document components.forEach(([Component, config]) => { const $elements = $scope.querySelectorAll( diff --git a/packages/govuk-frontend/src/govuk/components/character-count/character-count.mjs b/packages/govuk-frontend/src/govuk/components/character-count/character-count.mjs index c4623dfe0e..2ba9564544 100644 --- a/packages/govuk-frontend/src/govuk/components/character-count/character-count.mjs +++ b/packages/govuk-frontend/src/govuk/components/character-count/character-count.mjs @@ -128,7 +128,7 @@ export class CharacterCount extends GOVUKFrontendComponent { }) // Determine the limit attribute (characters or words) - this.maxLength = this.config.maxwords || this.config.maxlength || Infinity + this.maxLength = this.config.maxwords ?? this.config.maxlength ?? Infinity this.$module = $module this.$textarea = $textarea @@ -344,7 +344,7 @@ export class CharacterCount extends GOVUKFrontendComponent { */ count(text) { if (this.config.maxwords) { - const tokens = text.match(/\S+/g) || [] // Matches consecutive non-whitespace chars + const tokens = text.match(/\S+/g) ?? [] // Matches consecutive non-whitespace chars return tokens.length } else { return text.length diff --git a/packages/govuk-frontend/src/govuk/components/error-summary/error-summary.mjs b/packages/govuk-frontend/src/govuk/components/error-summary/error-summary.mjs index fa92fe03e5..ac8c9c50d5 100644 --- a/packages/govuk-frontend/src/govuk/components/error-summary/error-summary.mjs +++ b/packages/govuk-frontend/src/govuk/components/error-summary/error-summary.mjs @@ -187,7 +187,7 @@ export class ErrorSummary extends GOVUKFrontendComponent { } return ( - document.querySelector(`label[for='${$input.getAttribute('id')}']`) || + document.querySelector(`label[for='${$input.getAttribute('id')}']`) ?? $input.closest('label') ) } diff --git a/packages/govuk-frontend/src/govuk/components/tabs/tabs.mjs b/packages/govuk-frontend/src/govuk/components/tabs/tabs.mjs index 255d8bb59d..29d6b5f2cb 100644 --- a/packages/govuk-frontend/src/govuk/components/tabs/tabs.mjs +++ b/packages/govuk-frontend/src/govuk/components/tabs/tabs.mjs @@ -162,7 +162,7 @@ export class Tabs extends GOVUKFrontendComponent { }) // Show either the active tab according to the URL's hash or the first tab - const $activeTab = this.getTab(window.location.hash) || this.$tabs[0] + const $activeTab = this.getTab(window.location.hash) ?? this.$tabs[0] this.showTab($activeTab) diff --git a/packages/govuk-frontend/src/govuk/errors/index.mjs b/packages/govuk-frontend/src/govuk/errors/index.mjs index 17dea86d6a..71cbe86e61 100644 --- a/packages/govuk-frontend/src/govuk/errors/index.mjs +++ b/packages/govuk-frontend/src/govuk/errors/index.mjs @@ -76,7 +76,7 @@ export class ElementError extends GOVUKFrontendError { // Append reason message += element - ? ` is not of type ${expectedType || 'HTMLElement'}` + ? ` is not of type ${expectedType ?? 'HTMLElement'}` : ' not found' } diff --git a/packages/govuk-frontend/src/govuk/i18n.mjs b/packages/govuk-frontend/src/govuk/i18n.mjs index 77fc164048..d0632db1f1 100644 --- a/packages/govuk-frontend/src/govuk/i18n.mjs +++ b/packages/govuk-frontend/src/govuk/i18n.mjs @@ -19,7 +19,7 @@ export class I18n { this.translations = translations // The locale to use for PluralRules and NumberFormat - this.locale = config.locale || document.documentElement.lang || 'en' + this.locale = config.locale ?? (document.documentElement.lang || 'en') } /**