JavaScript Basics Variables

JavaScript Basics Variables

1. Variable Overview

1.1 Storage of variables in memory

Essence: A variable is a piece of space in memory that a program applies for to store data.

1.2 Use of variables

The use of variables is divided into two steps: 1. Declare variables 2. Assign values

1. Declare variables

//Declare a variable named age

var is a JS keyword used to declare a variable. After declaring a variable using this keyword, the computer will automatically allocate memory space for the variable. age is the name of the defined variable. We need to access the allocated space in the memory through the variable name.

2. Assignment

age = 10; //Assign the value of age variable to 10

3. Initialization of variables

var age = 10;

1.3 Variable Syntax Extension

1. Update variables

When a variable is reassigned, its original value will be overwritten and the variable value will be based on the last assigned value.

2. Declare multiple variables

When declaring multiple variables at the same time, just write one var, and separate multiple variable names with commas.

var age = 10,name = 'lili',sex = 2;

3. Special cases for declaring variables

Condition illustrate result

var age;

console.log(age);

Only declare without assigning value undefined
console.log(age); Use directly without declaration or assignment Report an error

age = 10;

console.log(age);

Use without declaration 10

1.5 Variable Naming Conventions

  • It is composed of letters (AZ az), numbers (0-9), underscores (_), and dollar signs ($), such as: usrAge, num01, _name
  • Strictly distinguish between uppercase and lowercase letters. var APP; and var app; are two variables.
  • Cannot start with a number
  • It cannot be a keyword or a reserved word, such as for, var, while
  • Variable names must be meaningful
  • Follow camelCase naming convention. The first letter is lowercase, and the first letter of the following words is capitalized. myFirstName
  • Recommended translation website: Youdao iCiBa

Summarize

This article ends here. I hope it can be helpful to you. I also hope that you can pay more attention to more content on 123WORDPRESS.COM!

You may also be interested in:
  • In-depth understanding of JavaScript variable objects
  • JavaScript variables and transformation details
  • Do you understand JavaScript variable types and conversions between variables?
  • Do you know variable declaration in JavaScript?
  • A brief talk about JavaScript variable promotion
  • How to turn local variables into global variables in JavaScript
  • Detailed explanation of JS ES6 variable destructuring assignment
  • Javascript beginner's guide to string concatenation and variable applications
  • A brief analysis of the principles and usage examples of JS variable promotion
  • Use of variables in JavaScript

<<:  Summary of the main attributes of the body tag

>>:  Problems and solutions when replacing Oracle with MySQL

Recommend

Detailed explanation of CSS sticky positioning position: sticky problem pit

Preface: position:sticky is a new attribute of CS...

CocosCreator Typescript makes Tetris game

Table of contents 1. Introduction 2. Several key ...

Discussion on the problem of iframe node initialization

Today I suddenly thought of reviewing the producti...

How to deploy nextcloud network disk using docker

NextCloud You can share any files or folders on y...

Detailed explanation of the use of Refs in React's three major attributes

Table of contents Class Component Functional Comp...

Example of converting spark rdd to dataframe and writing it into mysql

Dataframe is a new API introduced in Spark 1.3.0,...

Solution to the problem "Table mysql.plugin doesn't exist" when deploying MySQL

Today I deployed the free-installation version of...

Mysql date formatting and complex date range query

Table of contents Preface Query usage scenario ca...

C# implements MySQL command line backup and recovery

There are many tools available for backing up MyS...

Example usage of JavaScript tamper-proof object

Table of contents javascript tamper-proof object ...

Tutorial on installing Android Studio on Ubuntu 19 and below

Based on past experience, taking notes after comp...

Implement QR code scanning function through Vue

hint This plug-in can only be accessed under the ...

MySQL chooses the appropriate data type for id

Table of contents Summary of Distributed ID Solut...

How to implement input checkbox to expand the click range

XML/HTML CodeCopy content to clipboard < div s...