In Aura
if ($A.get("$Browser.formFactor") != 'DESKTOP') {
// do something for mobile only here
}
In LWC
import formFactorPropertyName from '@salesforce/client/formFactor'
if (formFactorPropertyName == "Large") {
// Large—A desktop client.
// Medium—A tablet client.
// Small—A phone client.
}