Alright, so you are interested in learning JavaScript. Poor you, but even worse than that is that you're learning it from me. I don't know JavaScript in any shape way or form. Technically we're learning this together.
If you're a novice programmer, the first thing you should realize is that languages aren't important, concepts are. I know enough to make me dangerous. You will be regurgitating "print" (ehrmm I mean console.log() ) statements in no time. You will likely hate it, until you don't. If you stick with me until the end of this thing we will learn how to build a bot for Hive together.
To better understanding our choice of language, let's talk about what JavaScript is. JavaScript started out as a language used by web developers to make the web more interactive/dynamic. Before JavaScript there were a whole lot of homogenous and boring web pages littering the web. JavaScript was developed by Netscape to make their browser pop. It's part of a traditional triad of web development: HTML, CSS, and JavaScript. I'm not going to dive into HTML and CSS as they aren't important to us (yet), but a great way to think about those is that HTML and CSS basically function like the markdown you use for Hive. Now think of all the other things that web pages/apps do. JavaScript makes up a majority of everything else: the calculations, interacting with components etc.
Everyone knows that computers speak in 1's and 0's. If you wrote everything in the language that the computer understands, you would probably want to jump off a bridge in a very short time. Fortunately, JS allows us the ability to create a human readable(ish) form that only mildly kills your willpower to live (functionally dead on the inside). You will get through this with sheer determination to one day too create a mega successful crypto "rug-pull" exit scam. After which you can follow the natural programmer progression and become a YouTuber. As this series continues I'll speak a little more about everything.
One cool thing about JavaScript is that it is interpreted (to that 1's and 0's language that the computer understands) by a browser. Instead of using fancy development environments that use up your space and resources, let's just use an online version to get us started.
I am going to suggest that you go here. Just delete all of the text inside and try out the stuff below. Whenever you are ready to run your code click "run".
The first thing to understand is we need to break up our code into chunks that the interpreter can communicate in the computer's language. Consider it grammar for the computer. We need to tell the computer what to do with the code we are writing. Many times we need to preface our code with a declaration. There are many declarations you can use, but let's start with a constant or "const". A constant is an immutable number, much like the data you store here on hive. We'll call ours "immutableNumber". We write this way as it is the normal convention for naming stuff. Notice also in the code below that we end our "sentence" with a semicolon or ";".
const immutableNumber = 1;
Let's break this down:
"const" is a declaration that means constant. The computer now knows that we want this line to be a constant.
"immutableNumber" is just the name of our constant. We used a special coding convention so we match other people and can easily understand each other.
"= 1" means we are assigning the value of "immutableNumber" to equal 1.
Finally ";" is just the period at the end of our sentence. The computer now knows that we are done with our "sentence" or assignment.
So cool, we have written a line of code. If you run it on replit what happens? Absolutely nothing. Technically, we are only assigning a value to a place in the memory of the computer. The name "immutableNumber" is just a human readable version of a place where that value is assigned. Something really important to get across is that "=" does not mean equals. It's not like algebra or something. You are literally saying, "hey computer, call that spot in the memory 'immutableNumber' and let it hold the number (integer) 1 for me.
To be able to see what we just wrote, we need to use a special piece of code that displays information to the console. We can do that with this:
console.log(immutableNumber);
Anything that we write inside the parentheses of the function above will display the value assigned to it.
If we assign a constant with text, we can display that to the console. I'll use the infamous "Hello World" as an example below:
const helloWorld = "Hello World";
We just assigned the place in the memory called "helloWorld" words (or strings) the value of "Hello World".
If i use the below statement, the console will "print" "Hello World".
console.log(helloWorld);
The final thing we'll learn about today is a comment. Comments are used to write yourself or other programmers notes about what your code is doing. This can be helpful when you're working on things that seem very complicated. If I use a "//" in front of a sentence I write, the interpreter ignores the line of code.
//This is a comment
This is all a lot to take in, and trust me, it gets much much worse. Do you want to be a big fancy Web3 developer or not? Let's stop here for today and pick up again later.
Homework:
Write a constant called "evilPlans" that are assigned a string of what you would like to do with JavaScript and print it to the console.
What happens when you reassign "evilPlans" with a new value in the same program?
Code your answers and use "```" before and after your code to share the results in the comments section below. If something doesn't work out as planned share your thoughts in the comments.
As always, if I did a really bad job explaining things, feel free to reach out and ask for help. I really don't mind.
JS is basically satans butthole of language. XD
I don't disagree. Unfortunately I haven't really found one that I fell in love with. School forces us to use Java because they essentially want us to be legacy CRUD app repair guys. I like that I have to type a lot less in JS, but if that's the case why not use Python right?
This made me to remember when I first was learning programming. It was really frustrating for me to the extent I gave up
Did you ever pick it back up? If not I'd love to help you get started.
Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!
Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).
You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support.