javascript JavaScript基础知识

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript JavaScript基础知识相关的知识,希望对你有一定的参考价值。

// Interpolating variables into a string
let myName = 'Andris'
let myCity = 'Budapest'
console.log(`My name is ${myName}. My favorite city is ${myCity}.`) // Writes to console (equal to Python print)

const newVariable = 3.1415 // Makes a new variable which cannot reassigned

// Basic if statement with AND function
let mood = 'sleepy';
let tirednessLevel = 6;

if (mood === 'sleepy' && tirednessLevel > 8){
  console.log('time to sleep')
}
else{
  console.log('not bed time yet')
}

// Short hand for if statements
let isLocked = false;

if (isLocked) {
  console.log('You will need a key to open the door.');
} else {
  console.log('You will not need a key to open the door.');
}
// This one does the same as bove, but is much shorter
isLocked ? console.log('You will need a key to open the door.') : console.log('You will not need a key to open the door.')

// Another example with a string value
favoritePhrase === 'Love That!' ? console.log('I love that!') : console.log("I don't love that!");

以上是关于javascript JavaScript基础知识的主要内容,如果未能解决你的问题,请参考以下文章

javascript Javascript的基础知识

javascript javascript基础知识

javascript JavaScript基础知识

javascript JavaScript语言基础知识

javascript Javascript基础知识

JavaScript学习---JavaScript基础知识