JavaScript Guide: Introduction to JavaScript
Console
- The console is a panel which displays important messages for developers.
- Calling the
.log()
method on theconsole
object will print or log to the console the data within parenthesis.
The string, Hello!
, is being printed to the console.
console.log("Hello!");
Output:
Hello!
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Try it for freeComments
- A comment is a useful note within a program.
- It is ignored by the program and exists solely for informational purposes to those reading your code.
Use two forward slashes //
for a single-line comment.
Use /*
at the start and */
at the end of a multi-line comment.
Single-line comment:
//Hey! I'm ignored by the program.
Multi-line comment:
/*Me too!This is all commented.*/
Data Types
String
- Any grouping of characters surrounded by single
''
or double""
quotes
'New York City'
Number
- Any number including decimals
40.7
Boolean
- true or false values
true
Null
- The absence of a value
null
Arithmetic Operators
Addition: +
Subtraction: -
Multiplication: *
Division: /
Remainder (modulo): %
- Returns the remainder of dividing the right-hand number by the left-hand number.
console.log(5 + 7);console.log(6 - 2);console.log(3 * 5);console.log(10 / 5);console.log(22 % 7);
Output:
12
4
15
2
5
String Concatenation
- String concatenation is the process of appending one string to another.
- Using the
+
operator on two strings, we can append the string on the right to the string on the left.
console.log('New ' + 'York');
Output:
New York
Properties
- A property is stored information about an instance of a data type.
- To utilize a property, append an instance with a period followed by the property name.
Appending the length
property on the instance of a string returns the number of characters in that string.
console.log("Codecademy".length);
Output:
10
Methods
- Methods are actions that can be performed on an instance of a data type.
- To utilize a method, append an instance with a period, (the
.
operator), the method name, and opening and closing parentheses.
Calling the .toUpperCase()
method on the string instance returns the string in all capital letters.
console.log('codecademy'.toUpperCase());
Output:
CODECADEMY
Built-in Objects
- Built-in objects are collections of methods and properties provided by JavaScript.
Calling the .ceil()
method on the built-in Math
object returns the next whole number rounded up.
console.log(Math.ceil(43.8));
Output:
44
'The Codecademy Team, composed of experienced educators and tech experts, is dedicated to making tech skills accessible to all. We empower learners worldwide with expert-reviewed content that develops and enhances the technical skills needed to advance and succeed in their careers.'
Meet the full teamRelated articles
- Article
Different ways of reversing a string in C++
Learn multiple methods for reversing a string in C++, from basic manual approaches (like loops, recursion, stacks) to using STL (Standard Template Library) functions, and compare their performance. - Article
Python Syntax Guide
Guide - Article
Why JavaScript Is Essential
Learn what is JavaScript and why it is the most popular programming language. Discover its history, web development role, backend capabilities, and future potential in technology.
Learn more on Codecademy
- Free course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner Friendly15 hours - Free course
Learn JavaScript: Fundamentals
Learn how to control the flow of a program and use JavaScript to power dynamic behaviors on websites.Beginner Friendly4 hours - Free course
Learn Intermediate JavaScript
Take your JavaScript knowledge to the next level by learning how to use advanced functions to create more efficient programs.Intermediate11 hours