Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Power BI
  3. Question
Power BI

How to assign aura:attribute for objects with default value null?

Asked by Elizabeth Clarke Apr 15, 2021 3.0K views 1 answer
Share

About this question

This must be a a very simple question, but may be I'm doing it wrong. I wanted to set default aura:attribute value to null on lightning component as below. e.g.


but this gives me selectedValue as a String, and not comparing with null in lightning javascript controller/helper code.
let selectedObj = component.get('v.selectedObj');
console.log('selectedObj: '+(selectedObj===null) +' string comparison: '+(selectedObj==='null')); component.set('v.selectedObj', null); console.log('selectedObj: '+(component.get('v.selectedObj')==null)+' string comparison: '+(component.get('v.selectedObj')=='null'));
Result:

selectedObj: false string comparison: true selectedObj: true string comparison: false Therefore I had to set null value explicitly in javascript controller at the initialization. e.g.

component.set('v.selectedObj', null);

Is this the correct approach to set null in javascript? are there any better alternatives to set default null value for aura:attribute? Cheers!


Your answer

1 Answer

More Power BI discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Power BI Blogs

Guides, tips and career advice on Power BI from JanBask experts.