Javascript Part 1. This is a brief description of all the…
By: Jonathan Bleibdrey
Tags: Javascript Tips, JavaScript, Javascript Development, Objects, Data Type

variables and Datatypes.

This is a brief description of all the parts that make up javascript. We start with variables and Datatypes.

Variables:

Variable is a container that holds a value (number, string, object..). The value of the variable can be changed(using var or let, not const). To use a variable, you must first declare it like so;

We initialize it with an equal sign then a value.

There are three different variables you can use:

(bare-bones concept’s)

var = this variable is allowed to be used everywhere(or Globally), and it can be reassigned. Let = this variable is only allowed to be called in certain areas(or local scope) and reassigned. Const = this variable is only allowed to be called in certain areas(or local scope) and can NOT be reassigned.

Think of variables as houses; you put “objects” in the houses. Then when you call on those houses, they output the values in the houses(If that makes sense…).

We could set a variable and then use it later on;

So, what's happening here?

We are setting two variables one to “myName” and another to “myLastName”. Then running console.log() (console.log is a method to output information in your console in browser). In between the parentheses, I put what we want to output, which is done with the “+” to “concatenate” two words (or join together.).

Thus leaving you with “jonathanBleibdrey,” there was no space in between, so that's why I ran it a second time to show you the original output.

moving on;

If we wanted to change the value of “myName” or “myLastName,” we would have to write the variable and change the value with “=” and the new value like so;

All we did is use “myName” and then a “=” sign to change any value we want it to be.

We use a “camel case convention”; the first word is always lowercase, and then every beginning letter of a word is capitalized…like, “myName” or “myLastName.”

You can also use numbers “0–9”, lowercase “a-z,” uppercase “A-Z” in your variables names.

IT IS CASE SENSITIVE, so “myName” and “MyName” are two different things.

Try to name the variable something intuitive or something that describes what value it is holding.

THE DONT’S OF VARIABLES:

Don't ever use underscores at the beginning of a variable name, like this “_button.” Don't ever put a number at the beginning of a variable. Don't use javascript “keywords” like var, const, if, for, function, this, etc.…

NEXT, we talk about;

DATA types:

There are SEVEN data types in javascript

Boolean returns a “true” or “false” value

If you look down below, we set the variable to data, and the value of that is true. We then use an “if-else statement” if the first value is true then it will return “hurray it worked”. If it is false, it would go to the next part or “else” and run “nope!.” So since data is equal to true, it returns that first console.log “hurray it worked”

I also switched the data value to false, which in turn skips over the first console.log because data doesn't equal true, so it goes straight past it and to the “else statement,” outputting “nope!”.

2. null means “no value.”

it's not going anywhere, DEAD INPUT(HAHA).

We use this sometimes when we cant return blank statements.

sometimes we use null for math because its the same thing as 0;

3.undefined is very similar to null(but not really). Undefined means a variable has not been declared or has been declared but not giving a value.

Here we set a variable, but don't give it a value.

You will also see this a lot if we don't set a value to a variable

We try to add 2 to it, we would get back “NaN” Which stands for “Not a number,” that's because it's undefined.

4. Number is pretty self-explanatory it's any number(look at the picture for examples)

one thing to mention you can have decimals and whole numbers, something to look out for.

5.String is anything that's a word, it's usually surrounded by quotations.

We set the variable to “fun” and the value to “bacon bits.” When we console.log it, we use the “+” to concatenate it to the other string.

6.symbol these are new to ES6, they have a unique identity and are immutable(value can not change).

With strings, if you had two variables that both had the same value of “Jonathan” they would return true. With symbols, they are unique and would return false.

7.objects collection of properties. A property is an association between a key and value.

Here we are setting myCar variable to be a “new object()”(basically making an empty object.) Then we are giving myCar key and values, by saying “myCar.make = “Ford” ”.(we are essentially setting the key and the value at the same time. You will see that sometimes people will make the keys first when first creating the object, then the value how we did it .)

Think of objects as Accordion Folders(myCar is what the whole folder holds), then we have the sub-levels (The keys make, model, doors) and then the values are what's actually inside those sub-folders(Ford, Mustang, 3).

ok, well, that was definitely the hitchhikers' guide to dummy javascript…! I hope this helped a little bit. See you all next time...

check out some more….

Javascript 1 (link to: variables and data types)

Javascript 2 (link to: numbers and strings)

Javascript 3 (link to: bracket notation and 20 diff string methods)

Javascript 4 (link to: functions and how they work)

Javascript 5 (link to: hoisting, comparison operators, and if-else statements)

Javascript 6 (link to: diff. Equal signs, null, and undefined)

Javascript 7 (link to: logical operator, &&, || and ternary operators)

Javascript 8 (link to: switch statements and arrays)

Javascript 9 (link to: commonly used arrays in javascript)

Javascript 10 (link to: Math. And parseInt Usage)