I am new to nodejs and JavaScript. I am writing automation framework using pageobject model using webdriver.io v5. I am facing two issues and would appreciate some clarification.
****************** Question 1 ******************
I have the following format code which works fine but returns Undefined as return value in main class
class ABC.js
***************
class ABC {
constructor() {};
extractCode() {
return (1 > 2).valueOf();// I am expecting false as output
}
}
module.exports = ABC;
*********** class D.js *******
var ABC = require('ABC');
class D extends ABC {
const abc = new ABC();
console.log(abc.extractCode());// I get undefined
}
************** Question 2 ************
class ABC.js
***************
class ABC {
constructor() {};
function extractCode() {
return (1 > 2).valueOf();// I am expecting false as output
}
}
module.exports = ABC;
I get the following error :
function extractCode() {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Unexpected identifier
Why is adding function keyword throwing error on JavaScript?