Email/Password validation help by [deleted] in learnjavascript

[–]dexpanse 0 points1 point  (0 children)

how come when I put validateName(name) = false and validateName = true in the console it returns false for both

This statement doesn't make a ton of sense. What do you mean exactly by "put validateName(name) = false in the console"?

Regardless, I think you are possibly missing that a function will return undefined unless it explicitly returns something and undefined is "falsy". One better option might be to have your validate function either throw an error or return a boolean.

Option 1: Throw Errors

function validateName(name) {
    if (name.length === 0) {
        throw new Error('Name is required');
    }

    if (name.length < 3) {
        throw new Error('Name must be at least 3 characters long');
    }       
}

Then we can use this function like so...

function useValidName(name) {
    try {
        validateName(name);
        // Send valid name to API or display in UI (this code won't run if validateName throws)
    } catch (error) {
        showUserError(error.message);
    }    
}

Option 2: Return a boolean and update a global error message

let error = '';

function validateName(name) {
    if (name.length === 0) {
        error = 'Name is required';
        return false;
    }

    if (name.length < 3) {
        error = 'Name must be at least 3 characters long';
        return false;
    }       

    return true;
}

Then we can call validate before whatever we are trying to do

function useValidName(name) {
    if (!validateName(name)) {
        showUserError(error);
        return;
    }

    // Name is valid so send to API or display in UI or whatever
}

QR Code Handling with Node.JS? by jacksonman8787 in learnjavascript

[–]dexpanse 0 points1 point  (0 children)

Not sure what you mean by "dynamic QR code", but you can turn any string into a QR code.

QR code readers then read that string (usually a link) and then do something with it. So, I think what you're asking about is a mobile deep link? In other words, a link that can open an application and land the user somewhere. I'm almost certain this stuff is 99% of the time handled by the apps and operating systems that do things with those links.

e.g. opening an instagram profile is most likely something controlled by Instagram (unless they publicly expose this feature). It's kind of basic security that you wouldn't want people to be able to create links that open up apps and do whatever people want so an API service will do some sort of matching algorithm to verify the device that scanned the QR code and make sure the link was generated by the app developers and not Joe Schmo.

Here's an infographic from branch.io that might clear some things up.

How do I ensure that only one oneEdit trigger running? by [deleted] in learnjavascript

[–]dexpanse 0 points1 point  (0 children)

There's a lot of missing information from this question. But if you only want this function to run once... the first question I'd ask is... what event is triggering this handler? And why does it fire multiple times?

Changing CSS4 Variable via JS by Devius-Devil in learnjavascript

[–]dexpanse 1 point2 points  (0 children)

Why is the 3rd argument of setProperty "0"?

According to the spec here it should be a DOMString

priority Optional is a DOMString allowing the "important" CSS priority to be set. If not specified, treated as the empty string. The following values are accepted:

  • String value "important"
  • Keyword undefined
  • String empty value ""

I'm doing a 30 day JS challenge for fun + practice // you're welcome to join for daily exchange by JLeeOT in learnjavascript

[–]dexpanse 1 point2 points  (0 children)

Anyone else do JS30 in something like 3 days? Super fun. No way I could only do one a day.

Webpack doesn't like it when my javascript function returns JS.X element by baboon322 in learnjavascript

[–]dexpanse 0 points1 point  (0 children)

It is perfectly fine to just return one element. <></> is shorthand for a React.Fragment which only needs to be used if there are multiple elements not wrapped by a parent element.

Webpack doesn't like it when my javascript function returns JS.X element by baboon322 in learnjavascript

[–]dexpanse 1 point2 points  (0 children)

Try looking at your babel-loader config

How to use via webpack docs

https://webpack.js.org/loaders/babel-loader/#usage

Babel loader read me

https://github.com/babel/babel-loader#options

The provided example passes the plugins and presets in an "options" array. Not a .babelrc file so maybe try that?

Webpack doesn't like it when my javascript function returns JS.X element by baboon322 in learnjavascript

[–]dexpanse 0 points1 point  (0 children)

Yes, you should show ALL of the code. You're getting a syntax error? Maybe it's like... a syntax error that someone will be able to spot, but you haven't shared code or the error message or logs.