« first day (4055 days earlier)      last day (900 days later) » 

3:51 AM
@Rana Thank you so much @Rana!! apologies i am just getting started with Javascript so how come just calling the function FortuneTeller won't work when we click on the button? instead we have to use function(){FortuneTeller('Ari', 'Taylor Swift', 'Hawaii', 8);}
 
 
2 hours later…
5:49 AM
No problem @cool-peaches, It is because JS render(or sort of run) the code when it reaches it. First you have written a function, when JS reaches this it will not run as that function is not called. Than you have written FortuneTeller('Ari', 'Taylor Swift', 'Hawaii', 8) after the function, so when JS reaches this it sees that above function is called and try to run that with provided values. All this is happening when script is loading . So you get alert when loaded upto this point.
After that you have called document.querySelector("button").addEventListener("click", FortuneTeller); , JS don't know what to enter the values in variables as it don't take var values from previous run of function. But if you write this: document.querySelector("button").addEventListener("click", FortuneTeller('Ari', 'Taylor Swift', 'Hawaii', 8)); , than also alert will be shown on load.
I too faced this problem at start and asked it in this question
So if you want button to execute the function that's why used a extra function
 
 
2 hours later…
8:05 AM
@Rana @Rana This makes a lot more sense! So is there any way we can trigger a function on the click of a button, but have the function written outside the scope of the button? Basically, we write the function first then specify the function to run on the click of a button?
 
 
2 hours later…
9:53 AM
How come when I use Object.keys(myObj).forEach(...) doesn't get renderd if i call it in my return (react)?
but I can do myArray.map(...), and it renders just fine
 
@Markus forEach always returns undefined.
 
so what happens to the thing i do within the forEach? :)
but basically I would have used map instead. I just used the wrong function?
 
10:10 AM
@Markus Nothing happens. It iterates over some values, it constructs some data, then sacrifices it to the garbage collector because it never returns it, thus it's never used.
 
10:21 AM
Thanks.
 
 
3 hours later…
1:22 PM
any TS experts, how can i resolve this?
console.log("Database with id of " + Def && Def.id + "' was found"); Object is possibly 'undefined' in Def.id
Strict mode error
Object is possibly undefined in Def.id?
can i do Def?.id
is this the best practice
 
That can still be undefined
 
can you suggest how to solve please
 
If Def was undefined. Realistically, you should have probably checked Def by this point whether it has an id or not. Or you can use (Def?.id ?? "") but it can be misleading.
 
ok thanks
How can i add a check for Def?
if(Def) { console.log("Database with id of " + Def && Def.id + "' was found"); }
should be ok right?
 
You shouldn't need Def && Def.id at this point - just Def.id. Assuming that the id is non-nullish.
 
1:30 PM
ok got it, thanks
 
Also, consider using template literals: console.log(`Database with id of ${Def.id}' was found`)
 
ok will do, out of curiosity, Is that a standard?
 
|| mdn template literals
 
TS also supports them natively.
Playground Link - compiling TS to ES5 - you can see the compiled output is correct for ES5. That's because TS does support template strings itself and converts them to appropriate JS construct.
 
1:36 PM
cool, thanks
 
2:10 PM
@VLAZ Argument of type 'unknown' is not assignable to parameter of type '{ code: string; }'.

handleError(err);
what is this error?
 
@faceturn Something returns unknown because the type isn't determinible or something. Hard to say exactly. Most likely err is unknown.
Are you using TS 4.4?
 
yes
 
And is err coming from a try/catch block?
 
yes
 
@faceturn Please don't post unformatted code - use the up arrow to edit your post, then hit Ctrl + K to format the code in that post. See the faq. You have 25 seconds to edit and format your message properly before it will be removed. Please separate code blocks from your actual question. Put your question in 1 message and then your code in a 2nd and format it.
 
2:14 PM
OK, then I know - this is a change with TS 4.4 - caught values are now unknown. Which is a change that makes sense but not to be introduced in 4.4 IMO. At any rate, you need to either verify err is an error with if (err instanceof Error) or do a type assertion if you're certain err as Error
 
1 message moved to Trash can
 
Or maybe err as any as Error - I can't remember if unknown required double assertion.
//check
try {
    foo();
} catch(err) {
    if (err instanceof Error) {
        handleError(err);
    } else {
        // you probably want to handle this
    }
}

//type assertion
try {
    foo();
} catch(err) {
    handleError(err as Error); //if you are certain it's an error
}
 
3:03 PM
@VLAZ Nah, not necessary
 
3:46 PM
for (let key in testObj) {
  if (key === "x") {
    testObj[key] = [];
  }
}
*facepalm* what an inefficient way to do this...
 
 
2 hours later…
6:08 PM
why <br> is a replaced element, infact it cannot have content?
 
6:19 PM
@DamodaraSahu ??
 
hi
 
I was studing replaced elements in html. In some articles i saw br element is in replaced elements list.
 
can somebody look at my question about react? stackoverflow.com/questions/70068505/…
 
6:36 PM
@DamodaraSahu You mean these? The ones like <img> where the rendered content is replaced with what they refer to (in the example of <img>)? Because <br> is not part of them. It's a void element so it can never even be replaced.
Or do you mean something else?
 
Hello
I have one Express question
const queryParam = (error, result) => {
  if (error) throw error;
  res.status(200).json(result);
};

exports.create_database = (req, res) => {
  const CREATE_DATABASE = "CREATE DATABASE nodemysql";
  db.query(CREATE_DATABASE, queryParam);
};
what parameters to provide for queryParam ?
because for now - ReferenceError: res is not defined
 
res.status(200).json(result); -> result.status(200).json(result); or rename your parameter to res
 
7:08 PM
Thank you
but now I have another error
throw err; // Rethrow non-MySQL errors
^

TypeError: result.status is not a function
this is code from customerController.js
so , I have
exports.get_all_customers = (req, res) => {
  const FETCH_CUSTOMERS = "SELECT * FROM Customers";
  db.query(FETCH_CUSTOMERS, queryParam);
};

exports.get_customer = (req, res) => {
  const GET_CUSTOMER_BY_ID = `SELECT * FROM Customers WHERE id = ${req.params.id}`;
  db.query(GET_CUSTOMER_BY_ID, queryParam);
};
but I have an issue when I try to reuse queryParam
 
8:05 PM
@VLAZ good advice, the staying an extra 5 mins is always a trap
 
8:53 PM
o/
 
9:16 PM
 
Hey guys, seem to be having some issues with mapping, can anybody have a look please?
 
@S.Code Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
 
 
2 hours later…
10:57 PM
posted on November 22, 2021 by Daniel Gagnon

The Beta channel is being updated to 96.0.4664.57 (Platform version: 14268.43.0) for most Chrome OS devices. If you find new issues, please let us know by visiting our forum or filing a bug. Interested in switching channels Find out how. You can submit feedback using ‘Report an issue...’ in the Chrome menu (3 vertical dots in the upper right corner of the brow

 

« first day (4055 days earlier)      last day (900 days later) »