What are the things I've learned so far in JavaScript?

 What are the things I've learned so far in JavaScript?

Variables

  • In the older version of JavaScript, 'var' was used to assign variables. 
  • Since the ES6 version of JavaScript, there are two new things (don't know what they're called) used to name variables: 'let' and 'const'
    • 'let' means the variable can be changed further down the line (have I got this right?)
    • 'const' means the variable stays the same, or, well... constant...
  • Variables that have not yet had a value assigned to them store the value of 'undefined' (... apparently ...)
  • Mathematical operators
    • +, -, *, /, and of course my favourite, Module, %
    • can also weirdly be assigned as +=, -=, and *=, etc., WHICH I DON'T GET.!!!
    • Also the increment and decrement operators... I saw this a lot in the Harvard CS50 course, which I did weeks 0 and 1 of, when he uses it in C; something like i++; i--;.
  • The typeof function... I don't know why it confuses me so much because they more or less had the same in Ruby and/or Python. 
    • I'm less confused about what it does
    • And more confused about the syntax and how to type it.

Strings

console.log()

I have to admit that I found print() (from Python) and even puts() (from Ruby) a bit more logical than this. However, I am determined to make JavaScript my language of choice, and indeed the love of my life, so I will persevere with this.

String Concatenation

Pretty easy - same as in any other programming language I've used before. Just put '+' e.g.

console.log('Hello ' + 'everyone '+ 'my name is Susanna');

will print

Hello everyone my name is Susanna
 to the console.

String Interpolation

I've seen similar things before but I've never seen anything quite as cool as this before. This is really, really cool. 

Example: 

let myName = Susanna;

let myAge = 28;

let myHobby = coding;

console.log(`My name is ${myName}. I am ${myAge} years old. My favourite hobby is ${myHobby}`);

This will print: My name is Susanna. I am 28 years old. My favourite hobby is coding.

You can then re-assign the variables:

myName = Beatrice;

myAge = 22;

myHobby = embroidery;

If you repeat the same line of code: (what would you call it? a function? a formula?)

console.log(`My name is ${myName}. I am ${myAge} years old. My favourite hobby is ${myHobby}`);

It will now print: 

My name is Beatrice. I am 22 years old. My favourite hobby is embroidery.

Data Types

There are 7 main data types in JavaScript. (I don't know if there are any more... or not?).
  • Numbers
  • Strings
  • Booleans
  • Undefined
  • Nulls
  • Symbols 
  • Objects
The first 6 have something in common: they are all primitive data types. Apparently that means they are more basic (hmm... sounds suspicious. how can anything be basic in JS? lol). 

  • Apparently, objects are more complex.

Other Stuff

  • An object is a thing which can have properties
  • You can find out an object's properties by using a full stop '.' after the object
  • for example, 'LORD VOLDEMORT'.length would return...14 I guess? I'm assuming the space counts, right?
  • Some objects have 'built in methods'
    • Again, you can access these with the full stop '.'
    • like 'LORD VOLDEMORT'.toLowerCase() would turn it into 'lord voldemort' (I'm assuming!!!).
    • Again, we can use the full stop '.' to access these things.

Built-In Objects

Arrrrrrrrrrrrrgh

Okay, maybe not so bad after all? According to codecademy, these are 'collections of methods and properties that JavaScript provides'.

Okay, so the two so far that I know are:

  • Math
  • Number
Does anyone know any more, though? Anyone know any else? Care to share them?

Also I had a meeting in a really cool meeting room at work today... so I messed around and got some cool pictures. This is me as usual, thinking about coding... And probably plotting some kind of evil world domination...



Comments

Popular posts from this blog

Hello World

Yosemite

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