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
How to set the dropdown value by clicking on a table row
Javascript – How to set the dropdown value by clicking on a table row
JavaScript
Attempting to increase the counter, when the object's tag exist
Javascript – Attempting to increase the counter, when the object’s tag exist
JavaScript
Cycle2 JS center active slide
Javascript – Cycle2 JS center active slide
JavaScript
Can import all THREE.js post processing modules as ES6 modules except OutputPass
Javascript – Can import all THREE.js post processing modules as ES6 modules except OutputPass
JavaScript
How to return closest match for an array in Google Sheets Appscript
Javascript – How to return closest match for an array in Google Sheets Appscript
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

How to set the dropdown value by clicking on a table row

Javascript – How to set the dropdown value by clicking on a table row

February 11, 2024
Attempting to increase the counter, when the object's tag exist

Javascript – Attempting to increase the counter, when the object’s tag exist

February 11, 2024
Cycle2 JS center active slide

Javascript – Cycle2 JS center active slide

February 10, 2024
Can import all THREE.js post processing modules as ES6 modules except OutputPass

Javascript – Can import all THREE.js post processing modules as ES6 modules except OutputPass

February 10, 2024
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?