JavaScript(JS) is a programming language that runs inside the internet browser. It was created in 1995.(HTML and CSS are not programming language â they set up style and structure rather than behavior). Despite having similar names, it is entirely different from Java, which is a programming language from the early 90s, originally intended to create interactive televisions.
Originally, JavaScript was used for front-end interaction. Now itâs also used for back-end. In general, you can use it to program the behavior of a webpage.
Before we can do anything fun with javascript, itâs important to understand the basics.
Why would you use JavaScript?
Add interactions to site that are input or time based
Manipulate HTML or CSS based on user input
Load additional resources
Add, edit, or remove classes
JavaScript, HTML, or CSS?
To edit the contents of a paragraph?
To style the page to have a blue background?
To change the background when a user clicks a button?
Console
The web console is a tool where you can write commands on a server directly into a webpage. In other words, itâs an easy way to test out javascript commands and see if theyâre working.
To open it up, go to a website hold down command, option and J(â„+â+J)or go to View / Developer / Javascript Console.
This is how it should look:
Â
Â
Â
Â
The JavaScript console is text only, and you can use it to communicate with the website using lines of codes. Itâs also where errors will be recorded.
Try sayingâHelloâ to the browser and see if it says anything back.
đ
Unless youâre using the correct syntax, youâll likely see an error. Try this instead:
alert("Hello Friend!")
Now that youâve made friends with your browser, you might be wondering whatâs going on.
Youâve done 4 things:
You called up the function, alert
alert(âHello Friend!â)
You utilized basic syntax, by starting with parentheses
alert(âHello Friend!â)
You typed a parameter, which is a string
alert(âHello Friend!â)
You utilized basic syntax, by ending with parentheses
Intro to JavaScript
Why would you use JavaScript?
JavaScript, HTML, or CSS?
Console
alert("Hello Friend!")
console.log("Hello Friend!")