Hello everyone, I just finished my first two weeks of coding bootcamp and I wanted to share some concepts I learned about Javascript. We'll start at the very basics, which is declaring a variable;
let or const number = 5
number
=> 5
when we declare this variable, we can access this anytime throughout the code later, unless the variable is within a function. the difference between const
and let
is that the value assigned to const cannot be reassigned, while the value of let can. Variables can also have words in them, or what as known as a string
. Next we have functions
;
function doAdd(){
return 2 + 2
}
doAdd()
=> 4
Basically the point of a function is to run code that we can call upon later. There are more technical concepts about where and when we can call functions and about scope, but I will not cover it in this post. We can also pass arguments into functions, making our dataset more dynamic;
function doSubtract(num1, num2){
return (num1 - num2)
}
doSubtract(2,6)
=> -4
We can pass any number into the parentheses as arguments when we call the function, giving us more power to work dynamically with data rather than static data. We also have Arrays
, which are declared like variables. let me show you a visual comparison of strings vs arrays;
//String
const Apple = "Macintosh"
Apple
=> Macintosh
//Array
const bigUsCities = ["Atlanta","Seattle","NYC","Los Angeles","Denver","Houston","Miami"];
bigUsCities
=> "Atlanta","Seattle","NYC","Los Angeles","Denver","Houston","Miami"
We also have objects
, which are used to store more specific data;
const contact = {
Name: "Jonny Appleseed",
State: "Colorado",
City: "Aurora",
PhoneNumber: "778-330-2389"
},
{
Name: "Kratos",
State: "Midgard",
City: "Unkown",
PhoneNumber: "1-888-447-5594"
}
all the values within objects are called keys
, and you can access that data by using key notation;
contact.name
=> "Jonny Appleseed"
The nice thing about objects and arrays and variables is that they are all datasets that we can access through functions, making our functions even more dynamic;
function contactCallList(){
contact.forEach((contact) => {
console.log(contact)
})
contactCallList()
=> {Name: "Jonny Appleseed", State: "Colorado", City: "Aurora", PhoneNumber: "778-330-2389"}{Name: "Kratos", State: "Midgard", City: "Unknown", PhoneNumber: "1-888-447-5594"}
There are many other ways to manipulate and get data from arrays and objects, but the main point is that we can use these to build functions and websites that can have whatever data input we have. This next week I will be building a personal project with another person in my cohort. In this post there were many other concepts such as the DOM, Databases, appending to the DOM, but for the simplicity of those reading I will not cover those topics but just cover these to begin to understand what coding is like. I have learned so much in the past two weeks and I will learn even more in the next 13. There has been so many frustrations and joys from learning code, but I wouldn't be doing anything else right now.
Top comments (0)