Back to Course

Introduction to JavaScript

0% Complete
0/0 Steps
  1. JavaScript: Basics
    9Topics
    |
    10 Quizzes
  2. JavaScript: Variables
    9Topics
    |
    10 Quizzes
  3. JavaScript: Conditional Statements
    10Topics
    |
    11 Quizzes
  4. JavaScript: Functions
    10Topics
    |
    11 Quizzes
  5. JavaScript: Scope
    6Topics
    |
    7 Quizzes
  6. JavaScript: Arrays
    11Topics
    |
    12 Quizzes
  7. JavaScript: Loops
    8Topics
    |
    9 Quizzes
  8. JavaScript: High Order Functions
    3Topics
    |
    4 Quizzes
  9. JavaScript: Iterators
    6Topics
    |
    6 Quizzes
Lesson 2, Topic 2
In Progress

JavaScript: var Variable

Yasin Cakal 29 Oct 2021
Lesson Progress
0% Complete

In 2015, many changes were made to the ES6 version of JavaScript. One of the most significant modifications was the addition of two new keywords, let and const, to create or define variables. Prior to the ES6, programmers could only declare variables using the var keyword.

var webTitle = 'CodeOfCode';
console.log(webTitle);
//Output: CodeOfCode

Consider the following example:

  1. The JavaScript keyword var, which stands for variable, creates or declares a new variable.
  2. The variable’s name is webTitle. Camel case is a JavaScript standard that allows you to capitalise in this manner. In camel casing, you unite words into one, lowercase the first word, then uppercase the initial letter of every word that follows. (For example, camelCaseEverything.)
  3. The assignment operator is =. It gives the variable webTitle the value CodeOfCode.
  4. The variable webTitle has the value CodeOfCode set to it. You might also state that the variable webTitle is initialised with the value CodeOfCode.
  5. After declaring the variable, the string value CodeOfCode is reported to the console using the variable name: console.log(webTitle).

When it comes to naming variables, there are few general guidelines to follow:

  • Variable names must not begin with a number.
  • Because variable names are case sensitive, webTitle and webtitle are distinct variables. It is not a good idea to create two variables with the same name but in distinct circumstances.
  • Keywords and variable names cannot be the same. Check out MDN’s keyword documentation for a comprehensive list of keywords.

Note: In the following tasks, we will discover why many programmers favour ES6’s let and const keywords for variables. Because there is still a lot of code written prior to ES6, knowing the pre-ES6 var keyword is useful.

Visit the MDN var documentation to learn more about var.

Responses

Leave a Reply

%d bloggers like this: