Share
Websites are comprised of multiple programming languages: HTML – Structure, CSS – Presentation & JS – Behavior
In order to write JavaScript programs you must know the basics of the JavaScript language. The rules and guidelines that makeup this language is called Syntax.
Syntax – the arrangement of words and phrases to create well-formed sentences in a language.
In this blog post for beginners we are going to cover some JavaScript terms and definitions as well as JavaScript data types.
Terms and Definitions you need to know
Statement – executable line of code
console.log( 'This is a statement' );
Expressions – produces or are values
Keywords – reserved JS words
Variables – generic containers for storing data. Should be full words, user camelCase.
JavaScript Data Types
- Boolean – true or false values
- String – literal characters
- Number – numeric values & math operations
- Null – empty value
- Undefined – data type s set but has no value
- Objects – data type that allows for a value to have properties
- Symbols – unique identifiers
Settings up Variables in JS
To create a variable you need to declare the name then assign a value.
Below is an example of a boolean variable
var isUserLoggedIn = true; if (isUserLoggedIn ) { console.log( 'User is logged in.' ); }
Below is an example of a string variable. Strings are characterized by data being wrapped in single quotations. You can concatenate strings using a plus sign.
var firstName = 'justin', lastName = 'estrada', fullName; console.log( firstName ); fullName = firstName + ' ' + lastName; console.log( fullName );
Below is an example of number variables.
var a = 5, b = 2, c; c = a * b; console.log( c );
There are different types of the data type Number as well.
- Integers – whole numbers
- Floating Points – decimal numbers
- Positive & Negative Infinity
What is Nan? Unique data type signifying something is Not a Number. Usually returned due to an error.
A useful native JavaScript object is ‘Math’. Example:
// PI property console.log( Math.PI ); // You can use powers and expressions console.log( Math.pow( 13, 13 ) );
Brief overview of JavaScript Objects
Objecets are a data type that allows for a value to have properties.
var person = { id : 1, name : 'Justin' }; // reassigning id person.id = 3; console.log( person.id );
What are JavaScript Symbols?
Symbols are a newer feature in JavaScript. Symbols are unique unchangeable values often used for naming custom properties.
var person = { id : 1, name : 'Justin' }, IS_ONLINE = Symbol(); // reassigning id person[IS_ONLINE] = true; console.log( person[IS_ONLINE] );
Symbols are useful for having values that can’t be overwritten.