JavaScript/SapUi5 Interview Questions

1) if you are using the datefilter and you want to calculate date difference then how wil you find this ?

   >> Ans

                     <DatePicker

id="DP1"

placeholder="Enter Date"

change="handleChange"

class="sapUiSmallMarginBottom"/>

then you will get selected date from change event. after that get current date using 

var date_1 = new Date('07/01/2022'); >> selected date

var date_2 = new Date(); >> todays date

var difference = date_2.getDate() - date_1.getDate();


2) Why we use map() method ?

>> Ans

map() method is used to create new array from existing one.

1) Example - 

numbers = [1, 2, 3, 4];

doubled = numbers.map(item => item * 2);  >> output  [2, 4, 6, 8]

2) Example - 

numbers1 = ['Tu', 'Eu', 'Ru', 'Tr']

newArray = numbers1.map(item => item + "A"); >>  output  ['TuA', 'EuA', 'RuA', 'TrA']


3) Why we use filter() method ? / how to find even and odd numbers ?

>> Ans

The filter() method is mainly used to filter the array. filter method is apply the condition on every element of the array. if the condition is true then it will shows in array if its false then it will not shows in array.

Example - 

1) numbers = [1, 2, 3, 4];

evens = numbers.filter(item => item % 2 === 0);

output >  [2, 4]

2) odds = numbers.filter(item => item % 2 != 0)

output > [1, 3]

3) const students = [

  { name: 'Quincy', grade: 96 },

  { name: 'Jason', grade: 84 },

  { name: 'Alexis', grade: 100 },

  { name: 'Sam', grade: 65 },

  { name: 'Katie', grade: 90 }

];

studentGrades = students.filter(student => student.grade >= 90);

[{name: 'Quincy', grade: 96}1: {name: 'Alexis', grade: 100}2: {name: 'Katie', grade: 90}]



4) Why we use reduce() method ? / how to find countof any objetcs?

>> Ans

The reduce() method is used to reduce the array size to number

var pets = ['dog', 'chicken', 'cat', 'dog', 'chicken', 'chicken', 'rabbit'];

var petCounts = pets.reduce(function(obj, pet){

    if (!obj[pet]) {

        obj[pet] = 1;

    } else {

        obj[pet]++;

    }

    return obj;

}, {});


Output:

    dog: 2, 

    chicken: 3, 

    cat: 1, 

    rabbit: 1 

 }

5) Selectors in Css - 

  • Simple selectors (select elements based on name, id, class)
  • Combinator selectors (select elements based on a specific relationship between them)
    • child selector (>)
    • adjacent sibling selector (+)
    • general sibling selector (~)
    • descendant selector (space)
  • Pseudo-class selectors (select elements based on a certain state)
    • selector:pseudo-class > a:link
  • Pseudo-elements selectors (select and style a part of an element)
    • selector::pseudo-element > p::first-line
  • Attribute selectors (select elements based on an attribute or attribute value)
    • a[target] >> a[target="_blank"]
6) Why we use factory functions in SAPUI5 ?

To generate a dynamic control we use factory functions.Factory function is the most powerful approach for creating the controls dynamically by using model data in UI5.

<Table visible="true" id="ID_DEMO"                                   
items="{ path:'demoModel>/results',factory:'.myFactory'}">
<columns>
<Column minScreenWidth="Tablet" demandPopin="true">
<Text text="Name" />
</Column>
<Column minScreenWidth="Tablet" demandPopin="true">
<Text text="City" />
</Column>
<Column minScreenWidth="Tablet" demandPopin="true">
<Text text="Amount" />
</Column>
</columns> 
</Table>


onInit: function(){
var arr = [{
"Name":"a",
"City":"w",
"Amount":10,
},
{
"Name":"b",
"City":"x",
"Amount":2,
},
{
"Name":"c",
"City":"y",
"Amount":0,
},
{
"Name":"d",
"City":"z",
"Amount":0,
},];
var demoModel =  new sap.ui.model.json.JSONModel({
"results": arr
});
this.getView().byId("ID_DEMO").setModel(demoModel,"demoModel");
}


myFactory :function(sId,oContext){
var Value = oContext.getProperty("Amount");
var element;
if(Value > 0){
element = new sap.m.Text({
text:"{demoModel>Amount}"
});
}
else{
element = new sap.m.Input({
value:"{demoModel>Amount}"
});
}
return new sap.m.ColumnListItem({
cells:[new sap.m.Text({
text:"{demoModel>Name}"
}),
new sap.m.Text({
text:"{demoModel>City}"
}),
element
]
});
}, 



7) use of neo-app.json sapui5 

neo-app.json file used to store information about the destination.

8) How to deploy code in Git ?

Step 1: Create a repository in the SAP Cloud Platform Cockpit/or it will provide you by basis team.
Step 2: The newly created Git Repository is displays in the list of repositories > When we click on the repository > it will display the remote link to the repository.
Step 3: Initialize the Repository
Step 4: Cloning a Repository
Step 5: Provide the URL to the Git Repository
Step 6: Once the cloning completed then it will shows you the master and all operations like 
    pull,push,merge.
Step 7: click on commit to commit the latest code
Step 8: then pull the code
Step 9: then merge the code

9) what is cloud Connector ?

A cloud controller is a tool that transfers data from on-premises to cloud storage. to achieve this functaonality we use hard drives/solid state drives.

10) Custom Controls in SAP UI5 

properties, aggregations, associations, and events




    Post a Comment

    Previous Post Next Post