By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
rocoderesrocoderes
  • Home
  • HTML & CSS
    • Login and Registration Form
    • Card Design
    • Loader
  • JavaScript
  • Python
  • Internet
  • Landing Pages
  • Tools
    • Google Drive Direct Download Link Generator
    • Word Count
  • Games
    • House Painter
Notification Show More
Latest News
Responding to and Tracking Key Presses
How to Work With Responding to and Tracking Key Presses
JavaScript
Passing a JavaScript Value Between HTML Pages
Passing a JavaScript Value Between HTML Pages
JavaScript
Compare Objects in an Array
JavaScript Problem: Compare Objects in an Array
JavaScript
Switching Name Order Using Capturing Groups in Regular Expressions
Switching Name Order Using Capturing Groups in Regular Expressions
JavaScript
Shuffling an Array
JavaScript Problem: How to Perform Shuffling an Array
JavaScript
Aa
Aa
rocoderesrocoderes
Search
  • Home
  • HTML & CSS
    • Login and Registration Form
    • Card Design
    • Loader
  • JavaScript
  • Python
  • Internet
  • Landing Pages
  • Tools
    • Google Drive Direct Download Link Generator
    • Word Count
  • Games
    • House Painter
Follow US
High Quality Design Resources for Free.
rocoderes > JavaScript > What are Variables And Values in JavaScript
JavaScript

What are Variables And Values in JavaScript

Admin
Last updated: 2022/11/24 at 4:30 AM
Admin
Share
2 Min Read
variables and values in javascript

Variable means anything that can vary. In JavaScript, variables hold the data value and it can be changed anytime.

Contents
Naming Variables Rules:Challenge Time

JavaScript uses reserved keyword var to declare a variable. A variable must have a unique name. You can assign a value to a variable using equal to (=) operator when you declare it or before using it.


Syntax :

var variable-name; 

var variable-name = value;

Example: Variable Declaration


var myName="patel";  //variable stores string value
var myAge=22;      // variable stores number value
var city;          //declared a variable without assigning a value
variables and values in javascript

Naming Variables Rules:

1)The first character must be a letter or an underscore(_) or a dollar($). You can’t use a number as the first character

Example:  


var myName="patel";  //valid
var _myName="rocoderes";   //valid
var $myAge=21;  //valid

var 1myname=”Beast”; //not valid





2)The rest of the variable name can include any letter, any number, or the underscore. can’t use any other character, including spaces.

Example:


var _myAge1=22;  //valid
var my Age=23;   //not valid

3)Variable names are case sensitive

Example:


var myAge=22;
console.log(myage); //its show ReferenceError: myage is not defined

4)no limit to the length of the variable name. 

5)you can’t use one of the javascript reserved words as a variable name.

Example:


var var=22;  //not valid

Challenge Time


var _myName="patel";
var _1my__name="ro";
var 1myname="coderes";
var $myName="Rocoderes";

try it yourself whether it is valid or not

Related

Subscribe to Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

TAGGED: variables-and-values-in-javascript
Share this Article
Facebook Twitter Email Print
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Posted by Admin
Follow:
Rocoderes is a blog you can learn HTML, CSS, JavaScript, React Js and Python along with creative coding stuff and free source code files.
Previous Article basic git commands Which Are Basic Git Commands? It’s Function
Next Article data types in javascript What are Data Types in JavaScript? With Example
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

- Advertisement -

You Might Also Like

Responding to and Tracking Key Presses

How to Work With Responding to and Tracking Key Presses

February 5, 2023
Passing a JavaScript Value Between HTML Pages

Passing a JavaScript Value Between HTML Pages

February 3, 2023
Compare Objects in an Array

JavaScript Problem: Compare Objects in an Array

January 30, 2023
Switching Name Order Using Capturing Groups in Regular Expressions

Switching Name Order Using Capturing Groups in Regular Expressions

January 29, 2023
rocoderesrocoderes
Follow US

Copyright © 2022 All Right Reserved By Rocoderes

  • Home
  • About us
  • Contact us
  • Disclaimer
Join Us!

Subscribe to our newsletter and never miss our latest news, podcasts etc.

Zero spam, Unsubscribe at any time.
Welcome Back!

Sign in to your account

Lost your password?