0% found this document useful (0 votes)
10 views7 pages

Sony Inerview Question&Ans

The document provides a comprehensive overview of various JavaScript concepts, including the differences between comparison operators, array methods, and dependency management tools like npm and npx. It also covers advanced topics such as promises, async/await, and the Page Object Model in test automation. Additionally, it explains the usage of ES6 features and the significance of the 'this' keyword in JavaScript.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views7 pages

Sony Inerview Question&Ans

The document provides a comprehensive overview of various JavaScript concepts, including the differences between comparison operators, array methods, and dependency management tools like npm and npx. It also covers advanced topics such as promises, async/await, and the Page Object Model in test automation. Additionally, it explains the usage of ES6 features and the significance of the 'this' keyword in JavaScript.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

1. difference between == and === operator ?

Ans: == and === both are comparision operators , we used to comparing 2 values.
== used comparing 2 values, if 2 values are same it will return true.
=== used to comparing both values and datatypes . if both statements equal
it will return true.

2. difference of filter and map method in array with examples?

Map: map we used to in order to make the changes in array data . and map based on
condtion it will modify the element and finally it will give the result with same
length.
Filter: Filter it will return tre or false result, based on condition which element
is true that element is push to array.

3. How tell me before hook hw many times will execute


before hook will execute before executing all the it block.

4.Difference between npm and npx?

npm (Node Package Manager):


a) npm is primarily used for managing and installing Node.js packages
(JavaScript libraries and dependencies) globally or locally within a project.
b) It is mainly used for tasks like installing packages, managing
dependencies, updating packages, and running scripts defined in a package.json
file.
c) You typically use npm to install packages like this: npm install
package-name.

npx (Node Package eXecute):


a) npx is a tool that comes bundled with npm (5.2.0 and higher) and is used
to execute Node.js packages from the npm registry without having to install them
globally or locally.
It is often used for running the packages using npx wdio run ./wdio.conf.js
followed by package name.

5. How you were installing the dependencies?


npm install followed by dependency name using this command i install dependencies,
once installation is done the dependency automatically added in package.json file.

6.take a string and give the occurrence of 'a' in that string?

function countOccurrencesOfA(inputString) {

inputString = inputString.toLowerCase();

let count = 0;

for (let i = 0; i < inputString.length; i++) {


if (inputString[i] === 'a') {
count++;
}
if(j<i){
break;
}

return count;
}

const inputString = "TestYantra";


const result = countOccurrencesOfA(inputString);
console.log(`The character 'a' occurs ${result} times in the string.`);

7.Take array store strings and print if a string having 'a' in it using async and
await?

const arrayOfStrings = ["apple", "banana", "cherry", "date", "grape"];


async function names(words){

for (const result of words) {

await new Promise((resolve) => setTimeout(resolve, 1000));


if (result.includes('a')) {
console.log(result);
}
}
}
names(arrayOfStrings)

8. difference between waitForClickable(), waitForEnabled()?

waitForClickable(): it is used to interact with element that might initially be


present on the page but not clickable , beacuse element might be hidden or disable
so that we used waitForClickable() it help to
ensure that element ready for interaction.

waitForEnabled(): It is useful when you have an element that is initially disabled


(e.g., a button that becomes enabled only after some other action or input). You
use waitForEnabled() to wait until the element is
enabled and can receive interactions.

9. list out the dependencies you have used?


the dependencies we used like chai , allure , wait untill, xlsx and etc.

10. write command to execiute script in webdriver io and Explain each?

Webdriver io Execution command is --- npx wdio run ./wdio.conf.js

Explanation>>>>>>> npx-- npx is a node package executor is come up with npm and it
is used for executing packages
wdio--- wdio is a webdriver io command line
interface and it is used to setup, configure , run , manage test suite and test
runner.
run---This is an sub command of the webdriver
io command line interface, used for running tests.
./wdio.conf.js --This file contain setting
such as test framework, browser capabilities, test file and other configuration
files.

11. which version support sync to async?

As of now we not use sync method , we use async to handle Asynchronous operation.

12.Differnce b/w dev-dependency and normal dependency (minimum 5 point)

Dependencies (dependencies):
a)Dependencies, often listed in a project's package.json file under the
"dependencies" field, are packages that are required for the application to run in
a production environment.
b) These packages are essential for the application's core functionality
and are installed when someone else installs or uses your package or application.
They are also installed when .
c)Examples of dependencies include web frameworks (e.g., Express.js),
database drivers (e.g., MongoDB driver), or utility libraries that your application
relies on to function.

Development Dependencies (devDependencies):


a)Development dependencies are packages listed in the "devDependencies" field
of a project's package.json file. These packages are used during the development
and testing phase of a b)project but are not required for the application to
run in a production environment.
c)Development dependencies typically include tools, libraries, or testing
frameworks that help with tasks such as code compilation, testing, linting, and
development workflows.

13. Difference b/w var, let, const with example ?


var:

Variables declared with var are function-scoped, meaning they are only
accessible within the function in which they are defined.
var variables are hoisted, which means that they are moved to the top of their
containing function or global scope during compilation.
They can be redeclared within the same scope without any errors.

javascript

function exampleVar() {
var x = 10;
if (true) {
var x = 20; // This reassigns the outer 'x'
console.log(x); // Outputs 20
}
console.log(x); // Outputs 20
}

let:
Variables declared with let are block-scoped, which means they are only
accessible within the block (e.g., if statement, for loop) in which they are
defined.
let variables are not hoisted, and they cannot be redeclared within the same
scope.

javascript

function exampleLet() {
let x = 10;
if (true) {
let x = 20; // This creates a new 'x' inside the block
console.log(x); // Outputs 20
}
console.log(x); // Outputs 10
}

const:
Variables declared with const are also block-scoped like let.
const variables, however, must be assigned a value when declared, and once
assigned, their value cannot be changed (they are constants).
Similar to let, const variables are not hoisted, and they cannot be redeclared
within the same scope.

function exampleConst() {
const x = 10;
if (true) {
const x = 20; // This creates a new 'x' inside the block
console.log(x); // Outputs 20
}
console.log(x); // Outputs 10
}

14. Explain about Object?

any entity having state and behaviour or properties and values is called as an
object.
in JavaScript object consist of properties and values (value can be of any
datatype),
property-value are separated by (:)
properties-values pair are separated by (,)

different ways of declaring an object


1] object_literal
2] new Object keyword:
3] constructor function:
4] class
5] object.create()

15. what is callback function with example?


If one function passing argument as an Another function that is called call back
function.

function A(){

var Detail={
'Name':"Kumar"
}
return Details;
}

function B(userdata){

console.log(userdata.Name)
}
B(A)

16. What is Arrow function and Limitation of Arrow function?

•Arrow function was introduced in ES6 version of JavaScript.


•This function is mainly used for code optimisation.
•In a single line of code, the function returns implicitly.
•When there are multiple lines of code we use brackets. When there are multiple
lines of code in the bracket we should write return explicitly to return the value
from the function.
Limitations:
a) We cannot use this keyword in Arrow function.

17. What is array destructuring?

Deriving an element from array and assign it to a reference variable is called


array destructuring.

18 . Function v/s Object?

Function:
• It is the block of code
• Used to perform some specific task
• It is reusable

Types of functions
1. Standard function / function declaration
2. Function expression
3. IIF (Immediately Invocable Function)
4. Arrow function

Object:
any entity having state and behaviour or properties and values is called as an
object.
in JavaScript object consist of properties and values (value can be of any
datatype),
property-value are separated by (:)
properties-values pair are separated by (,)

different ways of declaring an object


1] object_literal
2] new Object keyword:
3] constructor function:
4] class
5] object.create()

19. Remove the duplicates in the array using filter method?

var values=[1,1,2,3,4,3,5,6,7,6]
var result=[ ]
values.filter((element)=>{
if(result.include(element)==false){
result.push(element)
}
log(result)

20. . what are the ES6 features you have used in your project?
a)Class
b) Let and Const
c)Arrow function
d) Promise.
e) Template literals

21. what is 'this' keyword?


This keyword its represent current object refrence and its used to point to
the particular refrence inside a object.

22 . . How to work on POM class?


The Page Object Model (POM) is a design pattern used in test
automation
A Page Object class represents a single web page or Screen(Mobile)
which encapsulates elements on the page which we find using
different locator techniques
and also contains methods related the specific page
The main advantage is it separates the TestCode from UI implementation
and also easy maintenance(UI changes can be easily handled)

23. What is wdio cli?

The WDIO CLI, or WebdriverIO Command Line Interface, is a command-line tool


for running and managing end-to-end tests for web applications. WebdriverIO is a
popular open-source JavaScript framework that provides a set of bindings for the
WebDriver protocol, allowing you to automate interactions with web browsers and
perform automated testing of web applications.

The WDIO CLI is designed to simplify the process of setting up and running
WebdriverIO tests. It provides various commands and options for tasks such as test
configuration, test execution, test reporting, and more. Some common tasks you can
perform with the WDIO CLI include:

Test Configuration: You can use the WDIO CLI to initialize a new test project,
which sets up a basic project structure and configuration files for your tests.

Test Execution: The CLI allows you to run your WebdriverIO tests using different
configurations, browsers, and test suites. You can execute tests locally or on
remote WebDriver instances (e.g., Selenium Grid).

24. Program to handle array using async and await ?

var ele=["tys","yantra","pvt"]

async function A(data) {


for (const it of data) {
await new Promise((resove)=>setTimeout(resove,1000))
console.log(it);
}
}
A(ele)

25. Occurrence of character in the string ?

var str="programming"

for (let i = 0; i < str.length; i++) {

var count=0

for (let j = 0; j < str.length; j++) {

if (str[ i ]==str[ j ]) {
count++
}
if(j<i){
break
}
if (count>1) {
console.log(str [ i ]+"is"+count);
}
}

26. About this keyword?

this keywords used to point to the specified properties inside an object .

27. What is node js?

node js a back end javascript run time envionment and node js runs on javascript
engine then it will execute javascript code outside a browser.

28. Promise ?

A promise in the context of programming refers to a pattern used to handle


asynchronous operations. It is a JavaScript object that represents the eventual
completion or failure of an asynchronous operation and allows you to write more
readable and maintainable asynchronous code. Promises are commonly used for tasks
such as making HTTP requests, reading files, or any other operation that may take
some time to complete.

A promise can have one of three states:

Pending: The initial state, indicating that the operation is still in progress.
Fulfilled: The operation has completed successfully, and the promise now has a
result value.
Rejected: The operation has encountered an error, and the promise has a reason
for the failure.

Promises provide methods such as then() and catch() to handle the result or error
of an asynchronous operation in a more structured manner.

You might also like