JavaScript Syntax aka ARRRGH

JavaScript Syntax aka ARRRGH

JavaScript is hard. I mean, hard. I mean, the rules in most cases so far seem the same as in the other languages I have done (Python, Ruby), which is in line with what everyone has told me, that it is most important to know one language really well first because so many of the rules had been translated across.

I had planned long and hard. I had watched many YouTube videos. 

I had spoken to anyone and everyone who would listen to me.

And I had decided on Python. I had always planned for Python to be my 'first', strongest programming language. But then life happened. I went to a meetup for Async Brighton and I felt something I'd never felt before in my life. A kind of a... miracle. And an inspiration. I then went to an exhibit in London at the Science Museum on Sir Tim-Berners Lee, just two days later. And then I met with Rosana a week later. And they told me that I should learn the front-end first, to be the most useful at work the fastest.

And so that was that. That was meant to be. Life has meant for JavaScript to be my main programming language! 

And what can I say... that's great. Once I have wrapped my head around the syntax...

A quick shout-out to Ricardo first

First of all, I just wanted to shout-out my amazing friend, and very very dearly valued, colleague Ricardo, very very quickly.

Ricardo has been reading my blog (what a legend!). Ricardo is a very very talented and very highly skilled software engineer, with many years of experience under his belt. He also has the best sense of humour in the world. He cracks me up every time.

Now, what did Ricardo say? He told me to make my code easier to read. Erm... good point.

So from now on, I will be writing my code like this:

console.log('This is how I will be typing my code, if I remember to do it, lol')

Just Quickly: 

Here is a picture of my ultimate POWER PLACE - the Lac de la Lande in France, in the Vosges mountains. Photo not mine. I went there on hiking trips when I was 15 and 16. I HAVE NEVER FELT SO POWERFUL IN MY LIFE AS WHEN I WENT THERE AND STOOD ON THE DAM. 

I want to go back there more than anything else in the world one day (but can't drive so will need options).

Right, now onto the JavaScript stuff

In my last post, I just listed everything I learned, even the stuff that made sense to me. 

I now realise that was a bit to much. In order to really learn, and to remember going forward, I am now going to highlight some of the points that are basically unclear to me. 

console.log()

I feel extremely dumb starting with the most basic function in JavaScript.
But it is hard!!!

Why does it start with the 'console' bit and not with the log?

What is 'console' - is it the object?

What is 'log' - is it the method?

When compared to Ruby and Python, this seems quite illogical. But I'll get there, I promise. JavaScript is my one for life 💓💓

Properties

I don't know why but something just lit up when I wrote this. My whole body. I just felt a flash of inspiration. 

Maybe there's something in it for me...

This is all just so wonderful.

Ahem, back to the properties. 

So basically this: In this instance, what I am really talking about here, is retrieving property information.

The example that I am talking about here is the .length property (but I'm sure that there are many, many more, and this is part of the problem). 

so if I go

console.log(AWWWWWWW YEAH.length) it will output 13 to the console.

Well, now that I've written this all out, it all makes sense.
I guess my only remaining question on this is - what other properties exist in JavaScript that are similar to length?

Methods

This shouldn't be so difficult. I think it is just new. 

console.log('yo wazzup my name's Susanna you good bro'.toUpperCase) 

will print

YO WAZZUP MY NAME'S SUSANNA YOU GOOD BRO

Why do I find it so confusing? Methods are just

  • A full stop after the string 
  • They do something (e.g. like .toUpperCase, .toLowerCase, .trim)
  • There are probably loads and loads that I haven't learned yet but THAT IS FINE - I will LEARN THEM - I have TIME.

Built-In Objects

These are still driving me INSANE.

Math.random()

Math.floor()

Math.ceil()

Math.round()

Number.isInteger()


I think I will just learn these?

Why do they have brackets though? It is driving me INSANE.

I wonder, what other built-in objects does JavaScript have?

Built-In Mathematical Assignment Operators

These are like...

let x  = 1;

x = x + 1;

CAN ALSO BE WRITTEN AS

x += 1;

I do get how it works. Well, I do - but, I often still have to think about it. As: I don't get WHY?

String Concatenation with Variables

I'm just being a baby. I've done this before with Python. 

I just want to remember it.

console.log('Hello, I have' + 3 'pet rabbits');

N.b. I don't.

typeof operator

It's driving me INSANE. I DON'T GET IT. (although again, I have seen it before, in different languages). WHY WOULD ANYBODY NEED TO USE IT? WHY? SURELY YOU KNOW WHY TYPE OF VARIABLE YOUR VARIABLE IS?

Unless perhaps

  • You are taking over someone else's code
  • You are dealing with thousands of lines of code
  • You don't have a scarily good memory...

P.S. I've just remembered that I have all the documentation, and all the summaries, bookmarked from when I first did my two first JavaScript lessons. So maybe I will go through that all again later...

P.P.S. And then maybe I will write another post... 👀👀

Comments

Popular posts from this blog

Hello World

Yosemite

Two Lines of Thought, Makes Me Wonder What I'm Missing