JS questions for a newbie

Posted on
  • Hi, to begin with I should say that I am entirely new to all of this. I have never written code before, so please bear with me if some of my questions are self-evident to someone with any experience here. Right now I'm learning by examining the apps other people have written and figuring out how to implement the features I'd like on my own clock app while cross-referencing the Bangle.js 2 software reference document as well as broader JavaScript reference documents so I can form a better understanding of why things are used and when to use them appropriately.

    So the primary question on the tip of my tongue at the moment is exactly how important is it to a) create a scope in which all of my code sits so it can be unloaded correctly when I enter the launcher, b) avoid using 'const', and c) define functions via let, so that nothing is global and therefore (from what I'm understanding) still held in memory even when not in the clock app? Is this a remnant from the Bangle.js and its comparative lack of memory? I've noticed that while some apps like Anton Clock do this, many others don't. Even if so, is this still a practice that I should follow? As I'm learning from scratch I'd like to keep things somewhat clean and efficient.

    I think for most other things I'm a little clueless on I can find my way via trial and error, and this might be important in developing my skills, but I'd also like to be able to continue to ask questions here should I hit a stumbling block if that's okay! Thank you! I'm also sorry if my jargon isn't up to snuff.

    Also worth noting: I'm so happy to have discovered this project. Having a tangible output for basic code beyond the equivalent of a console printing "Hello world!" is vital to my sustained ability to continue learning without burning out. It's very rewarding to see incremental changes to a watch face that I'll be able to wear. The IDE and emulator also makes this so much easier to navigate via trial and error.

  • Hi, nice to see you here! Your way here is similar to mine :)

    Just in case you didn't open it yet: https://forum.espruino.com/conversations­/341830/#comment15028140

    The tutorials linked on that thread are very helpful when starting out.

    how important is it to a) create a scope in which all of my code sits so it can be unloaded correctly when I enter the launcher,

    Not important. I'd almost advice against it to start with. What it does is allow fastloading, described here: https://www.espruino.com/Bangle.js+Fast+­Load

    b) avoid using 'const', and c) define functions via let, so that nothing is global and therefore (from what I'm understanding) still held in memory even when not in the clock app?

    I would probably just go with using let for most things. If you want to you can learn about the difference of declaring variables with var, let and const (and declaring variables without any of them). But I mostly just go with let.

    Looking forward to see your watch face!

  • Thank you so much! Fast load! That's the term! Awesome. I really appreciate the guidance and the resources. I hope I can offer something interesting to the community with time. :)

  • Great! Glad you're getting stuck in!

    As @Ganblejs says I'd ignore Fast load for now - it shaves maybe 300ms off the time to switch to the launcher from the clock, so in most cases it won't be a big deal.

    Often when I'm developing I comment out the { and } right at the beginning and end of fast load clocks anyway:

    { // this
    let x = ...
    ...
    } // this
    

    It means that when you've uploaded your clock you can use the left-hand side of the IDE to manually check what's in variables or to call functions if you want to

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

JS questions for a newbie

Posted by Avatar for user157626 @user157626

Actions