Get Current User Id in Lightning Web Component

To get current user id in Lightning Web Component, we need to import the "@salesforce/user/Id" Salesforce scoped module.

LWC.html

<template>
    <div class="slds-text-heading_large slds-text-align_center">
        User Id : {currentUserId}
    </div>
</template>

LWC.js

import { LightningElement } from 'lwc';
import UserId from '@salesforce/user/Id';

export default class UserInformation extends LightningElement {
    currentUserId = UserId;
}

Output: