Site icon Hiroko Nishimura

JavaScript Statements and Syntax: JavaScript Newbies

This blogpost has notes about JavaScript Statements, JavaScript Syntax, and JavaScript Good Practices for beginners.

While I have years of experience with HTML/5 and CSS/3, it seems like in order to learn React JS, I need to learn some JavaScript first. In an effort to evaluate how much JavaScript one needs to know in order to begin learning React, I’m teaching myself JavaScript from scratch.

JavaScript Programs vs JavaScript Statements

In the same vein…

JavaScript Programs and JavaScript Statements are often called JavaScript Code.

JavaScript Data Types

JavaScript programs manipulate “values,” and all of those “values” belong to a “Data Type.”

Data Types:

JavaScript Statements

JavaScript Statements are made up of Values, Operators, Expressions, Keywords, and Comments.

// This is a Comment

var price1 = 7; // Assigning Variable (Value) to "price1" using Assignment Operator ( = )

var price2 = 6; // "var" is a Keyword

var total = price1 + price2; // Use Arithmetic Operator ( + ) to add "price1" and "price 2"; This is an Expression

JavaScript Syntax

JavaScript Syntax is a set of rules governing how JavaScript Programs are constructed.

JavaScript Values

There are two types of JavaScript Values: Literals and Variables.

var userName = ' Joe ' ; // String
var userNumber = 5 ; // Number
var schoolName ; // Use var Keyword to declare variables; Variable is undefined

var schoolName = "Centennial" ; // Assign value to Variable with equal sign

var schoolName = "Centennial" , schoolMascot = "Tigers" ; // Can declare multiple Variables in one statement by separating with commas

JavaScript Operators

There are many types of JavaScript Operators to help you assign values or do calculations.

JavaScript Expressions

JavaScript Expressions are combination of values, variables, and operators, which computes to a value.

JavaScript Keywords

JavaScript Keywords identify actions to be performed.

JavaScript Comments

JavaScript Comments are ignored when executing code. They are used to prevent execution when testing alternative code, or to explain code to make it more readable.

JavaScript Identifiers

JavaScript Identifiers are unique names to help identify variables, keywords, functions, and labels.

Here are some General Rules for constructing unique identifiers:

JavaScript Good Practices

There are some “Good Practices” to keep in mind when writing JavaScript, both for readability, and easier debugging.

JavaScript Display Possibilities

There are a few ways JavaScript can “display” data. I’m going to list a few major ones!

Trying Out JavaScript

I played around with a few new functions I learned with JavaScript today! I figured out how to hide/show HTML, and shrink/grow text sizes with document.getElementById( ).

You can run this code to see what it does here: w3schools Tryit Editor

<html>
<body>

<h2>What Can JavaScript Do?</h2>

<p>JavaScript can show hidden HTML elements.</p>

<p id="demo" style="display:none">Hello JavaScript!</p>

<button type="button" onclick="document.getElementById('demo').style.display='block'">Show Me!</button>

<button type="button" onclick="document.getElementById('demo').style.display='none'">Hide Me!!</button>

<button type="button" onclick="document.getElementById('demo').style.fontSize='50px'">Balloon Me!!!</button>

<button type="button" onclick="document.getElementById('demo').style.fontSize='12px'">Shrink Me!!!!</button>

</body>
</html> 

Sources and Resources

I’m starting out my JavaScript learnings through w3schools’ JavaScript Tutorial section. Some of the information is from the article “A re-introduction to JavaScript” from MDN web docs.

I’ve also had the opportunity to write a few articles for egghead.io for their React Handbook!

Exit mobile version