JavaScript Tutorial
JavaScript provides the foundation of 95% of all websites of the web. That is almost the entire web. Javascript is fast and continues to grow for ios and android. It's also used for front end and the back end with a framework like Node js. There are 77,000 jobs available for JavaScript Developers.
You have an HTML Parser the CSS Parser, and the JavaScript Engine. HTML makes the structure of the website and the navigation bar. The CSS is the animation and colors and the Javascript engine is the core, the 2-way train going back and forth between the website and the logic. Now, you can receive and listen to what the user is doing on the website and respond accordingly.
Now let's get into the coding of JavaScript. JavaScript is being used for Instagram, javascript is scrolling very nicely, and javascript is popping up for a picture. Netflix scrolling is Javascript and youtube liking/disliking is Javascript again.
Now, let's learn how to run JavaScript Code. We install Visual Studio Code and Create a Javascript Crash Course Folder. Ctrl + B hides the side panel in Visual Studio. doc + tab + save has the barebone HTML code.
console.log prints and alert puts a notification on the screen. Go to Chrome, Ctrl + O, run the file.
Now we can link a script to javascript file, that's how you actually code. Create an HTML file with ctrl + N and call it home.js. Now there's home.js and index.html.
2 slashes like java turns things into a comment and the comment sign tells the computer to
You can store strings and numbers into variables as well. Another cool things to show is to change the code on HTML page using JavaScript, and we can add HTML code using JavaScript. We can ask a user for his/her age, but it doesn't do anything with information yet, but you get an input. I can store prompt in a variable, though.
With JavaScript, you can do GUI development really fast. You can ask a user for his age.
The 2D JavaScript Tutorial we can have an integer or a floating number or lots of different operations on a number, or arithmetic of a number, meaning you can multiply a number.
Multiply is * divide is / mod is % Dealing with numbers is pretty standard, especially in Java. See the Leetcode list for more information.
Now, let's talk about functions.
//create the function
function fun() {
alert('this is a function');;
}
//calling the function
fun();
you have to invoke a function.
For functions we just need to
1. Create a function
2. Call the function
It's like creating a child and you need to call a child in order for it to invoke.
The idea behind functions is that it should do multiple things, which means taking in a name and returns to you, and says "hello" followed by your name.
Example of a function with string concatenation.
Functions can also take in arguments, or inputs, so we should have inputs outside of the function and the function should be taking that as the input. You add information before a function if a function is dependent on some information.
What if things have to be done multiple times? We use while loops and for loops to execute this.
Say we have some number equal to 0. What we'll do is we say while a number is less than 100 increment the number and log the number.
This is the code that does the following.
The for loop achieves the same things but has the same limit.
You can use let or var, and it's the same thing as naming something as a variable.
It would just run infinitely with while but for has a guaranteed stop.
Next, we want to go through data types.
These are examples of a number, string, object, boolean, array, undefined, and nul in JavaScript.
Now let's talk about strings.
You insert '\n' for a new line. We can also get fruit length be using .length function (no parentheses).
You can also get index of something that can be found in the string. If it doesn't exist, it returns -1.
We can also do slicing from 2 to 4 you get an, includes the first index but goes up to and does not include the last index. Including, and then up to.
You can also find and replace. Also, you can convert to upper case and to lower case. You can also get a character at an index or get index by referencing directly. You can also directly call a .split() method. You can either split by a comma or default character.
Now, let's talk about arrays in JavaScript. Let's say that we have fruits again and we create an array for the fruits.
Here are the 2 ways to create an array. You can only declare with lets once.
We can also set an array index again. You can also loop through an array.
Now, let's talk about the array common methods.
I can convert an array to a string, and I can convert it to the opposite to the split functionality. So you can give multiple arguments for console.log.You also have join and you can jin things be a character such as pear - apple - orange - pineapple.
pop() will pop off the last element of an array so now it will just read pear-apple-orange as a result.
Looks like you can modify the array in place as well, which is nice.
.shift() removes the first element of a list. .unshift added element to an array.
.concat() appends one array to the end of another.
You can slice an array, including the first index but up to the 4th but not including. .slice. .reverse() helps to reverse an array.
We can also call the sort method, as well as reverse and concatenate.
We can also insert elements to the array. We use the .push() element to add things to the array.
The next topic that we want to discuss is objects in JavaScript. They are also known as dictionaries in Python.
Say we have a student. We set the first name and the last names.
Seems like you can't access objects in JavaScript using indices anymore. That's been deprecated. You can change and increment values inside these objects. You can also do a little bit of object-oriented programming. You MUST reference things in objects with this (or self in python).
Let's now talk about conditionals and control flow. The target demographic is between 18 to 35.
Let's represent the code that has the idea.
Let's say day 0 is a Sunday and Day 6 is a Saturday, and we want to print out the proper weekday corresponding to the day. We can use the switch(input) statement for this. If case(6), then weekend, but if case(2) then we have a weekday.
JSON stands for JavaScript Object Notation, and is used to represent data. It uses APIs and configuration. In JSON, you would call it an array with objects inside of it.
The next thing we can do is to learn JSON. We go to the index we can create a script tag and inside of the tag,
we can take the JSON code, which is just Valid JavaScript
and you can see an array with 2 objects inside of it. JSON.parse is deprecated and outdated on April 25th, 2021, the day that this part of the article was written.


Comments
Post a Comment