The very basics of JavaScript…#30daysofJavaScript =>Day 1

Olajide Blessing Niniola
4 min readMar 4, 2021

Writing the first lines of code (Hello World!)

Did it work? Great!!! We have successfully been able to write our first line of code by writing Hello World to our console.

Code Structure

Before we write raw codes, it is important to know the building blocks of JavaScript, this would help in running into fewer errors and make your code easier to read. Following this structure can make it easy for other developers to work on your project.

  1. Semicolons: Semicolons are important in JavaScript, as little as it may sound be sure to put a semicolon(;) at the end of every line of code.
  2. Comments: As code becomes more complex and bulky, you might forget which code works for what. Therefore, it is very important to write comments about what your code works for. You don’t have to worry about it disrupting your work, the computer completely ignores them in the browser. One-line comments start with two forward slash characters //. Multiline comments start with a forward slash and an asterisk /* and end with an asterisk and a forward slash */.
  3. Camel Casing: This is of very important use in JavaScript. For example, if you want to name a variable, you should write firstName rather than FristName or firstname. This makes it readable and easier to manage.
  4. White-Space: JavaScript ignores white spaces in written codes, therefore you can add white lines to your code to make it more readable.

Common Features in JavaScript

Strings

Strings are values made up of text and can contain letters, numbers, symbols, punctuation, and even emoji. Strings are contained within a pair of either single quotation marks ‘ ’ or double quotation marks “ ”.

Properties in Strings

  1. length: A string’s length property keeps track of how many characters it has. Example: console.log(‘Hello World’ .length); The result will be 11 because obvious the ‘Hello World’ has 11 characters including the space.
  2. toLowerCase: A string’s toLowerCase method returns a copy of the string with its letters converted to lowercase. Numbers, symbols, and other characters are not affected. Example :console.log(‘Hello World’ .toLowerCase()). The result will be ‘hello world’ in small letters.
  3. toUpperCase: A string’s toUpperCase method returns a copy of the string with its letters converted to capitals. Numbers, symbols, and other characters are not affected. Example :console.log(‘Hello World’ .toUpperCase()). The result will be ‘hello world’ in capital letters.
Strings and their properties in JavaScript

Numbers

Numbers are values that can be used in mathematical operations. You don’t need any special syntax for numbers — just write them straight into JavaScript (that is you do not have to write them in quotes). Example : console.log (12345); . Read more about numbers in JavaScript here.

Booleans

Booleans are values that can be only one of two things: true or false.
Anything “on” or “off,” “yes” or “no,” or temporary is a usually good fit for a Boolean. It’s useful to store Booleans in variables to keep track of their values and change them over time.

Numbers and Booleans

Operators

Operators are the symbols between values that allow different operations like addition, subtraction, multiplication, and more. There are many operations in JavaScript but let us focus on the ones that are commonly used. Read more about operations here.

Operations in JavaScript

Bonus ==> Console Commands

This part would be very useful at the end of the day, as a matter of fact, we might see samples of it later in the other episodes.

About console: I made some research about several console commands and it happens that they are so many, more than just console.log(). A console is an object which provides access to the browser’s debugging console (I talked about how to access your browser console here). Let’s walk through the variety of console commands that exists.

  1. .log() : Outputs a message to the console
  2. .warn(): Outputs a warning message to the console.
  3. .error(): Outputs and error message to the console
  4. .clear(): Clears the console.
  5. .count(): Logs the number of times that particular call to count() has been called.
  6. .table(): Displays tabular form data as a table

Personal Experience

I’ll say the very basic is not hard to learn therefore making it tempting to skip but it is important to learn every bit of the basics you do not come up with errors and wonder why, whereas, the problem with that line of code just require a semicolon.

As always, thank you for reading.

Read my introduction yet? Read it here.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response